Rev 170: Try a workaround for the fact that I got a real-world failure to terminate subprocess. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Thu Jul 29 17:15:24 BST 2010


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

------------------------------------------------------------
revno: 170
revision-id: john at arbash-meinel.com-20100729161504-cmu4ojjqsxripnvo
parent: john at arbash-meinel.com-20100729160801-ijwda99oy3elaetm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Thu 2010-07-29 11:15:04 -0500
message:
  Try a workaround for the fact that I got a real-world failure to terminate subprocess.
  
  I think the process has already completed, so I'm just going to ignore the failure.
-------------- next part --------------
=== modified file 'meliae/files.py'
--- a/meliae/files.py	2010-07-28 20:44:49 +0000
+++ b/meliae/files.py	2010-07-29 16:15:04 +0000
@@ -63,14 +63,20 @@
         process.stderr.close()
         terminate = getattr(process, 'terminate', None)
         # terminate is a py2.6 thing
-        # XXX: I've observed a test failure when the subprocess has already
-        #      finished and then we try to call terminate, which then raises an
-        #      exception (not-allowed error). We should probably use a wrapper.
-        #      Either call process.poll() first, or trap the terminate for
-        #      exceptions. The error might also be that the process didn't
-        #      actually spawn yet...
         if terminate is not None:
-            return process.stdout, terminate
+            def terminate_or_pass():
+                # It seems that on windows, sometimes terminate() can raise 
+                # WindowsError: [Error 5] Access is denied
+                # My guess is that the process has actually completed, and is
+                # no longer running.
+                try:
+                    return terminate()
+                except OSError, e:
+                    sys.stderr.write('Ignoring failure to terminate process:'
+                                     ' %s\n' % (e,))
+                # We *could* check if process.poll() returns that the
+                # process has already exited, etc.
+            return process.stdout, terminate_or_pass
         else:
             # We would like to use process.wait() but that can cause a deadlock
             # if the child is still writing.



More information about the bazaar-commits mailing list