From 06ceecf6f55b4df362556c7dbad5aa1904ab6dcb Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Fri, 15 Jul 2016 02:10:26 +0300 Subject: [PATCH] Kill child processes when parent dies, and die on fatal errors (#265) --- lib/python/ray/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/python/ray/__init__.py b/lib/python/ray/__init__.py index 903307e7f..824d13831 100644 --- a/lib/python/ray/__init__.py +++ b/lib/python/ray/__init__.py @@ -6,6 +6,14 @@ WORKER_MODE = 1 SHELL_MODE = 2 PYTHON_MODE = 3 +import ctypes +# Windows only +if hasattr(ctypes, "windll"): + # Makes sure that all child processes die when we die + # Also makes sure that fatal crashes result in process termination rather than an error dialog (the latter is annoying since we have a lot of processes) + # This is done by associating all child processes with a "job" object that imposes this behavior. + (lambda kernel32: (lambda job: (lambda n: kernel32.SetInformationJobObject(job, 9, "\0" * 17 + chr(0x8 | 0x4 | 0x20) + "\0" * (n - 18), n))(0x90 if ctypes.sizeof(ctypes.c_void_p) > ctypes.sizeof(ctypes.c_int) else 0x70) and kernel32.AssignProcessToJobObject(job, ctypes.c_void_p(kernel32.GetCurrentProcess())))(ctypes.c_void_p(kernel32.CreateJobObjectW(None, None))) if kernel32 is not None else None)(ctypes.windll.kernel32) + import config import libraylib as lib import serialization