Commits

Jason R. Coombs committed a3e772e

Use subprocess module (if available). Works around #1196 on Python 2.4+.

Comments (0)

Files changed (2)

cherrypy/_cpcompat.py

 
     if sys.version_info < (2,6):
         daemon = property(__get_daemon, __set_daemon)
+
+# Prior to Python 2.4, there's no subprocess module.
+import subprocess
+if sys.version_info < (2,4):
+    def spawn(cmd, env, wait=False):
+        if wait:
+            wait_flag = os.P_WAIT
+        else:
+            wait_flag = os.P_NOWAIT
+        exe = cmd[0]
+        code = os.spawnve(wait_flag, exe, cmd, env)
+        if wait:
+            return code
+else:
+    def spawn(cmd, env, wait=False):
+        proc = subprocess.Popen(cmd, env=env)
+        if wait:
+            return proc.wait()

cherrypy/test/helper.py

 
 import cherrypy
 from cherrypy._cpcompat import basestring, copyitems, HTTPSConnection, ntob
+from cherrypy._cpcompat import spawn
 from cherrypy.lib import httputil
 from cherrypy.lib import gctools
 from cherrypy.lib.reprconf import unrepr
         """Start cherryd in a subprocess."""
         cherrypy._cpserver.wait_for_free_port(self.host, self.port)
 
-        args = [sys.executable, os.path.join(thisdir, '..', 'cherryd'),
-                '-c', self.config_file, '-p', self.pid_file]
+        args = [
+            os.path.join(thisdir, '..', 'cherryd'),
+            '-c', self.config_file,
+            '-p', self.pid_file,
+        ]
 
         if not isinstance(imports, (list, tuple)):
             imports = [imports]
             env['PYTHONPATH'] = os.pathsep.join((grandparentdir, env['PYTHONPATH']))
         else:
             env['PYTHONPATH'] = grandparentdir
+        res = spawn([sys.executable] + args, env, wait=self.wait)
         if self.wait:
-            self.exit_code = os.spawnve(os.P_WAIT, sys.executable, args, env)
+            self.exit_code = res
         else:
-            os.spawnve(os.P_NOWAIT, sys.executable, args, env)
             cherrypy._cpserver.wait_for_occupied_port(self.host, self.port)
 
         # Give the engine a wee bit more time to finish STARTING
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.