Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../multipro...
File: popen_fork.py
import os
[0] Fix | Delete
import signal
[1] Fix | Delete
[2] Fix | Delete
from . import util
[3] Fix | Delete
[4] Fix | Delete
__all__ = ['Popen']
[5] Fix | Delete
[6] Fix | Delete
#
[7] Fix | Delete
# Start child process using fork
[8] Fix | Delete
#
[9] Fix | Delete
[10] Fix | Delete
class Popen(object):
[11] Fix | Delete
method = 'fork'
[12] Fix | Delete
[13] Fix | Delete
def __init__(self, process_obj):
[14] Fix | Delete
util._flush_std_streams()
[15] Fix | Delete
self.returncode = None
[16] Fix | Delete
self.finalizer = None
[17] Fix | Delete
self._launch(process_obj)
[18] Fix | Delete
[19] Fix | Delete
def duplicate_for_child(self, fd):
[20] Fix | Delete
return fd
[21] Fix | Delete
[22] Fix | Delete
def poll(self, flag=os.WNOHANG):
[23] Fix | Delete
if self.returncode is None:
[24] Fix | Delete
try:
[25] Fix | Delete
pid, sts = os.waitpid(self.pid, flag)
[26] Fix | Delete
except OSError as e:
[27] Fix | Delete
# Child process not yet created. See #1731717
[28] Fix | Delete
# e.errno == errno.ECHILD == 10
[29] Fix | Delete
return None
[30] Fix | Delete
if pid == self.pid:
[31] Fix | Delete
if os.WIFSIGNALED(sts):
[32] Fix | Delete
self.returncode = -os.WTERMSIG(sts)
[33] Fix | Delete
else:
[34] Fix | Delete
assert os.WIFEXITED(sts), "Status is {:n}".format(sts)
[35] Fix | Delete
self.returncode = os.WEXITSTATUS(sts)
[36] Fix | Delete
return self.returncode
[37] Fix | Delete
[38] Fix | Delete
def wait(self, timeout=None):
[39] Fix | Delete
if self.returncode is None:
[40] Fix | Delete
if timeout is not None:
[41] Fix | Delete
from multiprocessing.connection import wait
[42] Fix | Delete
if not wait([self.sentinel], timeout):
[43] Fix | Delete
return None
[44] Fix | Delete
# This shouldn't block if wait() returned successfully.
[45] Fix | Delete
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
[46] Fix | Delete
return self.returncode
[47] Fix | Delete
[48] Fix | Delete
def _send_signal(self, sig):
[49] Fix | Delete
if self.returncode is None:
[50] Fix | Delete
try:
[51] Fix | Delete
os.kill(self.pid, sig)
[52] Fix | Delete
except ProcessLookupError:
[53] Fix | Delete
pass
[54] Fix | Delete
except OSError:
[55] Fix | Delete
if self.wait(timeout=0.1) is None:
[56] Fix | Delete
raise
[57] Fix | Delete
[58] Fix | Delete
def terminate(self):
[59] Fix | Delete
self._send_signal(signal.SIGTERM)
[60] Fix | Delete
[61] Fix | Delete
def kill(self):
[62] Fix | Delete
self._send_signal(signal.SIGKILL)
[63] Fix | Delete
[64] Fix | Delete
def _launch(self, process_obj):
[65] Fix | Delete
code = 1
[66] Fix | Delete
parent_r, child_w = os.pipe()
[67] Fix | Delete
child_r, parent_w = os.pipe()
[68] Fix | Delete
self.pid = os.fork()
[69] Fix | Delete
if self.pid == 0:
[70] Fix | Delete
try:
[71] Fix | Delete
os.close(parent_r)
[72] Fix | Delete
os.close(parent_w)
[73] Fix | Delete
code = process_obj._bootstrap(parent_sentinel=child_r)
[74] Fix | Delete
finally:
[75] Fix | Delete
os._exit(code)
[76] Fix | Delete
else:
[77] Fix | Delete
os.close(child_w)
[78] Fix | Delete
os.close(child_r)
[79] Fix | Delete
self.finalizer = util.Finalize(self, util.close_fds,
[80] Fix | Delete
(parent_r, parent_w,))
[81] Fix | Delete
self.sentinel = parent_r
[82] Fix | Delete
[83] Fix | Delete
def close(self):
[84] Fix | Delete
if self.finalizer is not None:
[85] Fix | Delete
self.finalizer()
[86] Fix | Delete
[87] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function