Monitor parent process for shutdown
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ data_dir = getDataDir()
|
|||||||
|
|
||||||
def start():
|
def start():
|
||||||
try:
|
try:
|
||||||
args = [sys.executable] + [os.path.join(os.environ['PWD'], __file__)] + sys.argv[1:]
|
args = [sys.executable] + [os.path.join(base_path, __file__)] + sys.argv[1:]
|
||||||
new_environ = os.environ.copy()
|
new_environ = os.environ.copy()
|
||||||
new_environ['cp_main'] = 'true'
|
new_environ['cp_main'] = 'true'
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
from ctypes import *
|
||||||
|
from ctypes.wintypes import *
|
||||||
|
import win32process
|
||||||
|
|
||||||
|
|
||||||
|
class PROCESSENTRY32(Structure):
|
||||||
|
_fields_ = (
|
||||||
|
('dwSize', DWORD,),
|
||||||
|
('cntUsage', DWORD,),
|
||||||
|
('th32ProcessID', DWORD,),
|
||||||
|
('th32DefaultHeapID', POINTER(ULONG),),
|
||||||
|
('th32ModuleID', DWORD,),
|
||||||
|
('cntThreads', DWORD,),
|
||||||
|
('th32ParentProcessID', DWORD,),
|
||||||
|
('pcPriClassBase', LONG,),
|
||||||
|
('dwFlags', DWORD,),
|
||||||
|
('szExeFile', c_char * MAX_PATH,),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def getppid(pid):
|
||||||
|
"""the Windows version of os.getppid"""
|
||||||
|
pe = PROCESSENTRY32()
|
||||||
|
pe.dwSize = sizeof(PROCESSENTRY32)
|
||||||
|
|
||||||
|
snapshot = windll.kernel32.CreateToolhelp32Snapshot(2, 0)
|
||||||
|
try:
|
||||||
|
if not windll.kernel32.Process32First(snapshot, byref(pe)):
|
||||||
|
raise WindowsError
|
||||||
|
while pe.th32ProcessID != pid:
|
||||||
|
if not windll.kernel32.Process32Next(snapshot, byref(pe)):
|
||||||
|
raise WindowsError
|
||||||
|
result = pe.th32ParentProcessID
|
||||||
|
finally:
|
||||||
|
windll.kernel32.CloseHandle(snapshot)
|
||||||
|
|
||||||
|
if result not in win32process.EnumProcesses():
|
||||||
|
result = 1
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
if not hasattr(os, 'getppid'):
|
||||||
|
os.getppid = getppid
|
||||||
@@ -11,12 +11,15 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
import getppid
|
||||||
|
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
class Core(Plugin):
|
class Core(Plugin):
|
||||||
|
|
||||||
ignore_restart = ['Core.crappyRestart', 'Core.crappyShutdown']
|
ignore_restart = ['Core.crappyRestart', 'Core.crappyShutdown', 'Core.monitorParent']
|
||||||
shutdown_started = False
|
shutdown_started = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -27,6 +30,7 @@ class Core(Plugin):
|
|||||||
addEvent('app.crappy_shutdown', self.crappyShutdown)
|
addEvent('app.crappy_shutdown', self.crappyShutdown)
|
||||||
addEvent('app.crappy_restart', self.crappyRestart)
|
addEvent('app.crappy_restart', self.crappyRestart)
|
||||||
addEvent('app.load', self.launchBrowser, priority = 1)
|
addEvent('app.load', self.launchBrowser, priority = 1)
|
||||||
|
addEvent('app.load', self.monitorParent)
|
||||||
addEvent('app.base_url', self.createBaseUrl)
|
addEvent('app.base_url', self.createBaseUrl)
|
||||||
addEvent('app.api_url', self.createApiUrl)
|
addEvent('app.api_url', self.createApiUrl)
|
||||||
|
|
||||||
@@ -34,6 +38,19 @@ class Core(Plugin):
|
|||||||
|
|
||||||
self.removeRestartFile()
|
self.removeRestartFile()
|
||||||
|
|
||||||
|
def monitorParent(self):
|
||||||
|
while 1:
|
||||||
|
if os.name == 'nt':
|
||||||
|
if os.getppid(os.getpid()) <= 1:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if os.getppid() <= 1:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
log.info('Starterscript has shutdown, shutdown subprocess')
|
||||||
|
fireEvent('app.crappy_shutdown')
|
||||||
|
|
||||||
def md5Password(self, value):
|
def md5Password(self, value):
|
||||||
return md5(value) if value else ''
|
return md5(value) if value else ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user