Commits

Tim Golden  committed 542f964 Draft

Improve reloader on Windows when python -m is used to run a package

  • Participants
  • Parent commits 48ec086

Comments (0)

Files changed (1)

File cherrypy/process/wspbus.py

 import atexit
 import os
 import sys
+import shlex
 import threading
 import time
 import traceback as _traceback
 import warnings
 
+import win32api
+
 from cherrypy._cpcompat import set
 
 # Here I save the value of os.getcwd(), which, if I am imported early enough,
         This must be called from the main thread, because certain platforms
         (OS X) don't allow execv to be called in a child thread very well.
         """
-        args = sys.argv[:]
-        self.log('Re-spawning %s' % ' '.join(args))
 
         if sys.platform[:4] == 'java':
             from _systemrestart import SystemRestart
             raise SystemRestart
+
+        if sys.platform == 'win32':
+            args = shlex.split(win32api.GetCommandLine(), posix=False)
+            executable = args[0]
         else:
-            args.insert(0, sys.executable)
-            if sys.platform == 'win32':
-                args = ['"%s"' % arg for arg in args]
+            args = sys.argv[:]
+            executable = sys.executable
+            args.insert(0, executable)
 
-            os.chdir(_startup_cwd)
-            if self.max_cloexec_files:
-                self._set_cloexec()
-            os.execv(sys.executable, args)
+        self.log('Re-spawning %s' % ' '.join(args))
+        os.chdir(_startup_cwd)
+        if self.max_cloexec_files:
+            self._set_cloexec()
+        os.execv(executable, args)
 
     def _set_cloexec(self):
         """Set the CLOEXEC flag on all open files (except stdin/out/err).