Rev 82: multiprocessing.Process only works with globals on Windows. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Fri Sep 11 18:39:37 BST 2009


At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

------------------------------------------------------------
revno: 82
revision-id: john at arbash-meinel.com-20090911173920-yfcry3l124m19eiv
parent: john at arbash-meinel.com-20090911173624-o748syrxfya6m4dd
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Fri 2009-09-11 12:39:20 -0500
message:
  multiprocessing.Process only works with globals on Windows.
  
  It uses cPickle to determine what function to run (since we don't have fork())
  as such, the function to run must be globally accessible, and not a nested
  function.
-------------- next part --------------
=== modified file 'meliae/files.py'
--- a/meliae/files.py	2009-09-11 17:36:24 +0000
+++ b/meliae/files.py	2009-09-11 17:39:20 +0000
@@ -64,17 +64,19 @@
         return process.stdout, process.terminate
 
 
+def _stream_file(filename, child):
+    gzip_source = gzip.GzipFile(filename, 'rb')
+    for line in gzip_source:
+        child.send(line)
+    child.send(None)
+
+
 def _open_mprocess(filename):
     if multiprocessing is None:
         # can't multiprocess, use inprocess gzip.
         return gzip.GzipFile(filename, mode='rb'), None
     parent, child = multiprocessing.Pipe(False)
-    def stream_file(filename, child):
-        gzip_source = gzip.GzipFile(filename, 'rb')
-        for line in gzip_source:
-            child.send(line)
-        child.send(None)
-    process = multiprocessing.Process(target=stream_file, args=(filename, child))
+    process = multiprocessing.Process(target=_stream_file, args=(filename, child))
     process.start()
     def iter_pipe():
         while True:



More information about the bazaar-commits mailing list