summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2012-12-26 08:01:04 -0500
committerJason R. Coombs <jaraco@jaraco.com>2012-12-26 08:01:04 -0500
commit041e5b361194d628874ed4721478d3e8dd5ccae2 (patch)
treed889852b2053d2e2cfa276f2897d931e57b28311
parentb8cfa09d45973e844dd497608006684b1c05ac52 (diff)
downloadcherrypy-041e5b361194d628874ed4721478d3e8dd5ccae2.tar.gz
Use subprocess module (if available). Works around #1196 on Python 2.4+.
-rw-r--r--cherrypy/_cpcompat.py18
-rw-r--r--cherrypy/test/helper.py12
2 files changed, 26 insertions, 4 deletions
diff --git a/cherrypy/_cpcompat.py b/cherrypy/_cpcompat.py
index 4e703703..4039b862 100644
--- a/cherrypy/_cpcompat.py
+++ b/cherrypy/_cpcompat.py
@@ -345,3 +345,21 @@ class SetDaemonProperty:
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()
diff --git a/cherrypy/test/helper.py b/cherrypy/test/helper.py
index ac19c210..11f3ab2c 100644
--- a/cherrypy/test/helper.py
+++ b/cherrypy/test/helper.py
@@ -14,6 +14,7 @@ import warnings
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
@@ -437,8 +438,11 @@ server.ssl_private_key: r'%s'
"""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]
@@ -457,10 +461,10 @@ server.ssl_private_key: r'%s'
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