]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Use subprocess.Popen on Windows, fixes #319
authorMaciej Małecki <maciej.malecki@notimplemented.org>
Mon, 22 Aug 2011 13:01:01 +0000 (15:01 +0200)
committerBen Darnell <ben@bendarnell.com>
Sun, 28 Aug 2011 06:30:22 +0000 (23:30 -0700)
tornado/autoreload.py

index d27182d78ce7601d72d6459c56b7d5058bc9c4bc..277dbbdce24f79ce229665521ef98cf1c8cfa286 100644 (file)
@@ -33,6 +33,7 @@ import logging
 import os
 import sys
 import types
+import subprocess
 
 from tornado import ioloop
 from tornado import process
@@ -141,23 +142,30 @@ def _reload():
         # ioloop.set_blocking_log_threshold so it doesn't fire
         # after the exec.
         signal.setitimer(signal.ITIMER_REAL, 0, 0)
-    try:
-        os.execv(sys.executable, [sys.executable] + sys.argv)
-    except OSError:
-        # Mac OS X versions prior to 10.6 do not support execv in
-        # a process that contains multiple threads.  Instead of
-        # re-executing in the current process, start a new one
-        # and cause the current process to exit.  This isn't
-        # ideal since the new process is detached from the parent
-        # terminal and thus cannot easily be killed with ctrl-C,
-        # but it's better than not being able to autoreload at
-        # all.
-        # Unfortunately the errno returned in this case does not
-        # appear to be consistent, so we can't easily check for
-        # this error specifically.
-        os.spawnv(os.P_NOWAIT, sys.executable,
-                  [sys.executable] + sys.argv)
+    if sys.platform == 'win32':
+        # os.execv is broken on Windows and can't properly parse command line
+        # arguments and executable name if they containt whitespaces. subprocess
+        # fixes thath behavior.
+        subprocess.Popen([sys.executable] + sys.argv)
         sys.exit(0)
+    else:
+        try:
+            os.execv(sys.executable, [sys.executable] + sys.argv)
+        except OSError:
+            # Mac OS X versions prior to 10.6 do not support execv in
+            # a process that contains multiple threads.  Instead of
+            # re-executing in the current process, start a new one
+            # and cause the current process to exit.  This isn't
+            # ideal since the new process is detached from the parent
+            # terminal and thus cannot easily be killed with ctrl-C,
+            # but it's better than not being able to autoreload at
+            # all.
+            # Unfortunately the errno returned in this case does not
+            # appear to be consistent, so we can't easily check for
+            # this error specifically.
+            os.spawnv(os.P_NOWAIT, sys.executable,
+                      [sys.executable] + sys.argv)
+            sys.exit(0)
 
 _USAGE = """\
 Usage: