[csw-devel] SF.net SVN: gar:[20022] csw/mgar/gar/v2-yann/lib/python

chninkel at users.sourceforge.net chninkel at users.sourceforge.net
Fri Jan 4 17:57:42 CET 2013


Revision: 20022
          http://gar.svn.sourceforge.net/gar/?rev=20022&view=rev
Author:   chninkel
Date:     2013-01-04 16:57:41 +0000 (Fri, 04 Jan 2013)
Log Message:
-----------
gar/v2-yann: make the shell timeout option more reliable

Modified Paths:
--------------
    csw/mgar/gar/v2-yann/lib/python/database.py
    csw/mgar/gar/v2-yann/lib/python/inspective_package.py

Modified: csw/mgar/gar/v2-yann/lib/python/database.py
===================================================================
--- csw/mgar/gar/v2-yann/lib/python/database.py	2013-01-04 10:27:41 UTC (rev 20021)
+++ csw/mgar/gar/v2-yann/lib/python/database.py	2013-01-04 16:57:41 UTC (rev 20022)
@@ -10,7 +10,7 @@
 import system_pkgmap
 
 CONFIG_DB_SCHEMA = "db_schema_version"
-DB_SCHEMA_VERSION = 7L
+DB_SCHEMA_VERSION = 8L
 TABLES_THAT_NEED_UPDATES = (m.CswFile,)
 TABLES = TABLES_THAT_NEED_UPDATES + (
             m.Architecture,
@@ -159,8 +159,8 @@
       except sqlobject.dberrors.OperationalError, e:
         logging.error("Could not create table %r: %s", table, e)
         raise
-        
 
+
   def InitialDataImport(self):
     """Imports initial data into the db.
 

Modified: csw/mgar/gar/v2-yann/lib/python/inspective_package.py
===================================================================
--- csw/mgar/gar/v2-yann/lib/python/inspective_package.py	2013-01-04 10:27:41 UTC (rev 20021)
+++ csw/mgar/gar/v2-yann/lib/python/inspective_package.py	2013-01-04 16:57:41 UTC (rev 20022)
@@ -81,6 +81,9 @@
 class TimeoutExpired(Exception):
     pass
 
+def TimeoutHandler(signum, frame):
+  raise TimeoutExpired
+
 def ShellCommand(args, env=None, timeout=None):
   logging.debug("Running: %s", args)
   proc = subprocess.Popen(args,
@@ -91,23 +94,18 @@
   # Python 3.3 have the timeout option
   # we have to roughly emulate it with python 2.x
   if timeout:
-    max_time = time.time() + timeout
-    while True:
-      proc.poll()
-      if proc.returncode is None:
-        time.sleep(0.1)
-        if time.time() >= max_time:
-          # we will all processes from the same process group
-          # in case the process spawned some children
-          os.kill(-proc.pid, signal.SIGKILL)
-          msg = "Process %s killed after timeout expiration" % args
-          raise TimeoutExpired(msg)
-      else:
-        break
+    signal.signal(signal.SIGALRM, TimeoutHandler)
+    signal.alarm(timeout)
 
-  stdout, stderr = proc.communicate()
-  retcode = proc.wait()
+  try:
+    stdout, stderr = proc.communicate()
+    signal.alarm(0)
+  except TimeoutExpired:
+    os.kill(-proc.pid, signal.SIGKILL)
+    msg = "Process %s killed after timeout expiration" % args
+    raise TimeoutExpired(msg)
 
+  retcode = proc.wait()
   return retcode, stdout, stderr
 
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list