@@ -90,45 +90,7 @@ def is_root() -> bool:
9090 return os .geteuid () == 0
9191
9292
93- libc : Optional [ctypes .CDLL ] = None
94-
95-
96- def prctl (* argv : Any ) -> int :
97- global libc
98- if libc is None :
99- libc = ctypes .CDLL ("libc.so.6" , use_errno = True )
100- return cast (int , libc .prctl (* argv ))
101-
102-
103- PR_SET_PDEATHSIG = 1
104-
105-
106- def set_child_termination_on_parent_death () -> int :
107- ret = prctl (PR_SET_PDEATHSIG , signal .SIGTERM )
108- if ret != 0 :
109- errno = ctypes .get_errno ()
110- logger .warning (
111- f"Failed to set parent-death signal on child process. errno: { errno } , strerror: { os .strerror (errno )} "
112- )
113- return ret
114-
115-
116- def wrap_callbacks (callbacks : List [Callable ]) -> Callable :
117- # Expects array of callback.
118- # Returns one callback that call each one of them, and returns the retval of last callback
119- def wrapper () -> Any :
120- ret = None
121- for cb in callbacks :
122- ret = cb ()
123-
124- return ret
125-
126- return wrapper
127-
128-
129- def start_process (
130- cmd : Union [str , List [str ]], via_staticx : bool = False , term_on_parent_death : bool = True , ** kwargs : Any
131- ) -> Popen :
93+ def start_process (cmd : Union [str , List [str ]], via_staticx : bool = False , ** kwargs : Any ) -> Popen :
13294 if isinstance (cmd , str ):
13395 cmd = [cmd ]
13496
@@ -150,19 +112,12 @@ def start_process(
150112 env = env if env is not None else os .environ .copy ()
151113 env .update ({"LD_LIBRARY_PATH" : "" })
152114
153- if is_windows ():
154- cur_preexec_fn = None # preexec_fn is not supported on Windows platforms. subprocess.py reports this.
155- else :
156- cur_preexec_fn = kwargs .pop ("preexec_fn" , os .setpgrp )
157- if term_on_parent_death :
158- cur_preexec_fn = wrap_callbacks ([set_child_termination_on_parent_death , cur_preexec_fn ])
159-
160115 popen = Popen (
161116 cmd ,
162117 stdout = kwargs .pop ("stdout" , subprocess .PIPE ),
163118 stderr = kwargs .pop ("stderr" , subprocess .PIPE ),
164119 stdin = subprocess .PIPE ,
165- preexec_fn = cur_preexec_fn ,
120+ start_new_session = is_linux (), # TODO: change to "process_group" after upgrade to Python 3.11+
166121 env = env ,
167122 ** kwargs ,
168123 )
0 commit comments