gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject svn commit: r161446 - gump/branches/Gump3/pygump/python/gump/util/
Date Fri, 15 Apr 2005 12:37:22 GMT
Author: leosimons
Date: Fri Apr 15 05:37:21 2005
New Revision: 161446

Documentation for executor module.

* pygump/python/gump/util/ add basic usage documentation (GUMP-98). Also improve
the 'reaping' algorithm to exit as soon as it has nothing more to do.


Modified: gump/branches/Gump3/pygump/python/gump/util/
--- gump/branches/Gump3/pygump/python/gump/util/ (original)
+++ gump/branches/Gump3/pygump/python/gump/util/ Fri Apr 15 05:37:21 2005
@@ -17,7 +17,18 @@
 """This module provides a thin wrapper around the subprocess library.
 On posix platforms, it does process group management to allow us to clean up
-misbehaved processes."""
+misbehaved processes.
+To start using this module, simply replace all imports of the subprocess
+module with imports of the gump.util.executor module. It defines a Popen
+class that has the same behaviour as the Popen class in the subprocess
+Next, near the end of your application (right before you're calling
+system.exit(), usually), add a call to the clean_up_processes() method. This
+will attempt to clean up any leftover children created by this module. Note
+that doing this can take some time depending on how well-behaved your children
 __copyright__ = "Copyright (c) 2004-2005 The Apache Software Foundation"
 __license__   = ""
@@ -105,7 +116,7 @@
                      cwd=cwd, env=env, universal_newlines=universal_newlines,
                      startupinfo=startupinfo, creationflags=creationflags)
-    def clean_up_processes(timeout):
+    def clean_up_processes(timeout=300):
         """This function can be called prior to program exit to attempt to
         kill all our running children that were created using this module."""
@@ -139,7 +150,7 @@
                 if e.errno == errno.ESRCH:
-    def _reap_children(pgrp_list, timeout=300):
+    def _reap_children(pgrp_list, timeout):
         # NOTE: this function edits pgrp_list
         # keep reaping until the timeout expires, or we finish
@@ -147,6 +158,11 @@
         # keep reaping until all pgrps are done, or we run out of time
         while pgrp_list and time.time() < end_time:
+            # if there's no groups left, we're done, so let's
+            # exit early!
+            if len(pgrp_list) == 0:
+                break
             # pause for a bit while processes work on exiting. this pause is
             # at the top, so we can also pause right after the killpg()

View raw message