+def _reexec():
+ """reexecute openerp-server process with (nearly) the same arguments"""
+ if openerp.tools.osutil.is_running_as_nt_service():
+ subprocess.call('net stop {0} && net start {0}'.format(nt_service_name), shell=True)
+ exe = os.path.basename(sys.executable)
+ strip_args = ['-d', '-u']
+ a = sys.argv[:]
+ args = [x for i, x in enumerate(a) if x not in strip_args and a[max(i - 1, 0)] not in strip_args]
+ if not args or args[0] != exe:
+ args.insert(0, exe)
+ os.execv(sys.executable, args)
+
+def restart_server():
+ if openerp.multi_process:
+ raise NotImplementedError("Multicorn is not supported (but gunicorn was)")
+ pid = openerp.wsgi.core.arbiter_pid
+ os.kill(pid, signal.SIGHUP)
+ else:
+ if os.name == 'nt':
+ def reborn():
+ stop_services()
+ _reexec()
+
+ # run in a thread to let the current thread return response to the caller.
+ threading.Thread(target=reborn).start()
+ else:
+ openerp.phoenix = True
+ os.kill(os.getpid(), signal.SIGINT)