Remove Unix-centric Zombie-process removal that eats Windows

This commit is contained in:
Griatch 2018-01-27 10:57:33 +01:00
parent fa4c59a662
commit 403b6c352a
2 changed files with 31 additions and 17 deletions

View file

@ -481,6 +481,11 @@ Others, like migrate, test and shell is passed on to Django."""
# #
# ------------------------------------------------------------ # ------------------------------------------------------------
def _is_windows():
return os.name == 'nt'
def _print_info(portal_info_dict, server_info_dict): def _print_info(portal_info_dict, server_info_dict):
""" """
Format info dicts from the Portal/Server for display Format info dicts from the Portal/Server for display
@ -811,7 +816,7 @@ def start_evennia(pprofiler=False, sprofiler=False):
def _portal_not_running(fail): def _portal_not_running(fail):
print("Portal starting {}...".format("(under cProfile)" if pprofiler else "")) print("Portal starting {}...".format("(under cProfile)" if pprofiler else ""))
try: try:
if os.name == 'nt': if _is_windows():
# Windows requires special care # Windows requires special care
create_no_window = 0x08000000 create_no_window = 0x08000000
Popen(portal_cmd, env=getenv(), bufsize=-1, Popen(portal_cmd, env=getenv(), bufsize=-1,
@ -1349,7 +1354,7 @@ def getenv():
env (dict): Environment global dict. env (dict): Environment global dict.
""" """
sep = ";" if os.name == 'nt' else ":" sep = ";" if _is_windows() else ":"
env = os.environ.copy() env = os.environ.copy()
env['PYTHONPATH'] = sep.join(sys.path) env['PYTHONPATH'] = sep.join(sys.path)
return env return env
@ -1409,7 +1414,7 @@ def kill(pidfile, component='Server', callback=None, errback=None, killsignal=SI
Ignored on Windows. Ignored on Windows.
""" """
if os.name == 'nt': if _is_windows():
# Windows signal sending is very limited. # Windows signal sending is very limited.
from win32api import GenerateConsoleCtrlEvent, SetConsoleCtrlHandler from win32api import GenerateConsoleCtrlEvent, SetConsoleCtrlHandler
try: try:
@ -1427,7 +1432,7 @@ def kill(pidfile, component='Server', callback=None, errback=None, killsignal=SI
# Linux/Unix/Mac can send kill signal directly to specific PIDs. # Linux/Unix/Mac can send kill signal directly to specific PIDs.
pid = get_pid(pidfile) pid = get_pid(pidfile)
if pid: if pid:
if os.name == 'nt': if _is_windows():
os.remove(pidfile) os.remove(pidfile)
try: try:
os.kill(int(pid), killsignal) os.kill(int(pid), killsignal)
@ -1607,7 +1612,7 @@ def init_game_directory(path, check_db=True):
print(ERROR_LOGDIR_MISSING.format(logfiles=errstr)) print(ERROR_LOGDIR_MISSING.format(logfiles=errstr))
sys.exit() sys.exit()
if os.name == 'nt': if _is_windows():
# We need to handle Windows twisted separately. We create a # We need to handle Windows twisted separately. We create a
# batchfile in game/server, linking to the actual binary # batchfile in game/server, linking to the actual binary
@ -1754,12 +1759,12 @@ def run_menu():
elif inp == 6: elif inp == 6:
stop_server_only() stop_server_only()
elif inp == 7: elif inp == 7:
if os.name == 'nt': if _is_windows():
print("Windows can't send kill signals by PID. Use option 8 instead.") print("Windows can't send kill signals by PID. Use option 8 instead.")
else: else:
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
elif inp == 8: elif inp == 8:
if os.name == 'nt': if _is_windows():
kill(None) kill(None)
else: else:
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
@ -1937,9 +1942,15 @@ def main():
elif option == 'sstop': elif option == 'sstop':
stop_server_only() stop_server_only()
elif option == 'kill': elif option == 'kill':
if _is_windows():
kill(None)
else:
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
kill(PORTAL_PIDFILE, 'Portal') kill(PORTAL_PIDFILE, 'Portal')
elif option == 'skill': elif option == 'skill':
if _is_windows():
print("This is not supported on Windows. Use 'evennia kill' instead.")
else:
kill(SERVER_PIDFILE, 'Server') kill(SERVER_PIDFILE, 'Server')
elif option != "noop": elif option != "noop":
# pass-through to django manager # pass-through to django manager

View file

@ -9,10 +9,14 @@ import sys
from twisted.internet import protocol from twisted.internet import protocol
from evennia.server.portal import amp from evennia.server.portal import amp
from django.conf import settings from django.conf import settings
from subprocess import Popen, STDOUT, PIPE from subprocess import Popen, STDOUT
from evennia.utils import logger from evennia.utils import logger
def _is_windows():
return os.name == 'nt'
def getenv(): def getenv():
""" """
Get current environment and add PYTHONPATH. Get current environment and add PYTHONPATH.
@ -21,7 +25,7 @@ def getenv():
env (dict): Environment global dict. env (dict): Environment global dict.
""" """
sep = ";" if os.name == 'nt' else ":" sep = ";" if _is_windows() else ":"
env = os.environ.copy() env = os.environ.copy()
env['PYTHONPATH'] = sep.join(sys.path) env['PYTHONPATH'] = sep.join(sys.path)
return env return env
@ -156,7 +160,7 @@ class AMPServerProtocol(amp.AMPMultiConnectionProtocol):
# eventual errors happening before the Server has # eventual errors happening before the Server has
# opened its logger. # opened its logger.
try: try:
if os.name == 'nt': if _is_windows():
# Windows requires special care # Windows requires special care
create_no_window = 0x08000000 create_no_window = 0x08000000
process = Popen(server_twistd_cmd, env=getenv(), bufsize=-1, process = Popen(server_twistd_cmd, env=getenv(), bufsize=-1,
@ -171,11 +175,10 @@ class AMPServerProtocol(amp.AMPMultiConnectionProtocol):
self.factory.portal.server_twistd_cmd = server_twistd_cmd self.factory.portal.server_twistd_cmd = server_twistd_cmd
logfile.flush() logfile.flush()
if process: if process and not _is_windows():
# avoid zombie-process # avoid zombie-process on Unix/BSD
process.wait() process.wait()
return process.pid return
return 0
def wait_for_disconnect(self, callback, *args, **kwargs): def wait_for_disconnect(self, callback, *args, **kwargs):
""" """