[GRASS-SVN] r48225 - grass/trunk/scripts/m.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 9 18:29:55 EDT 2011


Author: glynn
Date: 2011-09-09 15:29:54 -0700 (Fri, 09 Sep 2011)
New Revision: 48225

Modified:
   grass/trunk/scripts/m.proj/m.proj.py
Log:
Fix deadlock (for real, hopefully)


Modified: grass/trunk/scripts/m.proj/m.proj.py
===================================================================
--- grass/trunk/scripts/m.proj/m.proj.py	2011-09-09 18:38:00 UTC (rev 48224)
+++ grass/trunk/scripts/m.proj/m.proj.py	2011-09-09 22:29:54 UTC (rev 48225)
@@ -88,8 +88,27 @@
 
 import sys
 import os
+import threading
 from grass.script import core as grass
 
+class TrThread(threading.Thread):
+    def __init__(self, ifs, inf, outf):
+        threading.Thread.__init__(self)
+        self.ifs = ifs
+        self.inf = inf
+        self.outf = outf
+
+    def run(self):
+        while True:
+            line = self.inf.readline()
+            if not line:
+                break
+            line = line.replace(self.ifs, ' ')
+            self.outf.write(line)
+            self.outf.flush()
+
+        self.outf.close()
+
 def main():
     input = options['input']
     output = options['output']
@@ -237,21 +256,13 @@
     cmd = ['cs2cs'] + copyinp + outfmt + in_proj.split() + ['+to'] + out_proj.split()
     p = grass.Popen(cmd, stdin = grass.PIPE, stdout = grass.PIPE)
 
-    while True:
-	line = inf.readline()
-	if not line:
-	    break
-	line = line.replace(ifs, ' ')
-	p.stdin.write(line)
-	p.stdin.flush()
+    tr = TrThread(ifs, inf, p.stdin)
+    tr.start()
 
-    p.stdin.close()
-    p.stdin = None
-
     if not copy_input:
 	if include_header:
 	    outf.write("x%sy%sz\n" % (ofs, ofs))
-	for line in p.communicate()[0].splitlines():
+	for line in p.stdout:
 	    x, yz = line.split('\t')
 	    y, z = yz.split(' ')
 	    outf.write('%s%s%s%s%s\n' % \
@@ -259,13 +270,15 @@
     else:
 	if include_header:
 	    outf.write("input_x%sinput_y%sx%sy%sz\n" % (ofs, ofs, ofs, ofs))
-	for line in p.communicate()[0].splitlines():
+	for line in p.stdout:
 	    inX, therest, z = line.split(' ')
 	    inY, x, y = therest.split('\t')
 	    outf.write('%s%s%s%s%s%s%s%s%s\n' % \
                        (inX.strip(), ofs, inY.strip(), ofs, x.strip(), \
 		        ofs, y.strip(), ofs, z.strip()))
 
+    p.wait()
+
     if p.returncode != 0:
 	grass.warning(_("Projection transform probably failed, please investigate"))
 



More information about the grass-commit mailing list