Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to python 3.11.8 and 3.12.2 #176

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions py3.11/README_MODS
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,138 @@ diff Python-3.11.6/Lib/test/_test_multiprocessing.py Python-3.11.7/Lib/test/_tes
> support.print_warning(f"multiprocessing.Manager still has "
> f"{multiprocessing.active_children()} "
> f"active children after {dt:.1f} seconds")
# ----------------------------------------------------------------------
diff Python-3.11.7/Lib/multiprocessing/managers.py Python-3.11.8/Lib/multiprocessing/managers.py
156c156
< self.listener = Listener(address=address, backlog=16)
---
> self.listener = Listener(address=address, backlog=128)
diff Python-3.11.7/Lib/multiprocessing/popen_spawn_win32.py Python-3.11.8/Lib/multiprocessing/popen_spawn_win32.py
104,115c104,117
< if self.returncode is None:
< if timeout is None:
< msecs = _winapi.INFINITE
< else:
< msecs = max(0, int(timeout * 1000 + 0.5))
<
< res = _winapi.WaitForSingleObject(int(self._handle), msecs)
< if res == _winapi.WAIT_OBJECT_0:
< code = _winapi.GetExitCodeProcess(self._handle)
< if code == TERMINATE:
< code = -signal.SIGTERM
< self.returncode = code
---
> if self.returncode is not None:
> return self.returncode
>
> if timeout is None:
> msecs = _winapi.INFINITE
> else:
> msecs = max(0, int(timeout * 1000 + 0.5))
>
> res = _winapi.WaitForSingleObject(int(self._handle), msecs)
> if res == _winapi.WAIT_OBJECT_0:
> code = _winapi.GetExitCodeProcess(self._handle)
> if code == TERMINATE:
> code = -signal.SIGTERM
> self.returncode = code
123,134c125,140
< if self.returncode is None:
< try:
< _winapi.TerminateProcess(int(self._handle), TERMINATE)
< except PermissionError:
< # ERROR_ACCESS_DENIED (winerror 5) is received when the
< # process already died.
< code = _winapi.GetExitCodeProcess(int(self._handle))
< if code == _winapi.STILL_ACTIVE:
< raise
< self.returncode = code
< else:
< self.returncode = -signal.SIGTERM
---
> if self.returncode is not None:
> return
>
> try:
> _winapi.TerminateProcess(int(self._handle), TERMINATE)
> except PermissionError:
> # ERROR_ACCESS_DENIED (winerror 5) is received when the
> # process already died.
> code = _winapi.GetExitCodeProcess(int(self._handle))
> if code == _winapi.STILL_ACTIVE:
> raise
>
> # gh-113009: Don't set self.returncode. Even if GetExitCodeProcess()
> # returns an exit code different than STILL_ACTIVE, the process can
> # still be running. Only set self.returncode once WaitForSingleObject()
> # returns WAIT_OBJECT_0 in wait().
diff Python-3.11.7/Lib/multiprocessing/resource_sharer.py Python-3.11.8/Lib/multiprocessing/resource_sharer.py
126c126
< self._listener = Listener(authkey=process.current_process().authkey)
---
> self._listener = Listener(authkey=process.current_process().authkey, backlog=128)
diff Python-3.11.7/Lib/multiprocessing/util.py Python-3.11.8/Lib/multiprocessing/util.py
46c46
< _logger.log(SUBDEBUG, msg, *args)
---
> _logger.log(SUBDEBUG, msg, *args, stacklevel=2)
50c50
< _logger.log(DEBUG, msg, *args)
---
> _logger.log(DEBUG, msg, *args, stacklevel=2)
54c54
< _logger.log(INFO, msg, *args)
---
> _logger.log(INFO, msg, *args, stacklevel=2)
58c58
< _logger.log(SUBWARNING, msg, *args)
---
> _logger.log(SUBWARNING, msg, *args, stacklevel=2)
133c133,136
< rmtree(tempdir)
---
> def onerror(func, path, err_info):
> if not issubclass(err_info[0], FileNotFoundError):
> raise
> rmtree(tempdir, onerror=onerror)
diff Python-3.11.7/Lib/test/_test_multiprocessing.py Python-3.11.8/Lib/test/_test_multiprocessing.py
2695a2696,2703
> sleep_time = support.LONG_TIMEOUT
>
> if self.TYPE == 'threads':
> # Thread pool workers can't be forced to quit, so if the first
> # task starts early enough, we will end up waiting for it.
> # Sleep for a shorter time, so the test doesn't block.
> sleep_time = 1
>
2697c2705
< args = [support.LONG_TIMEOUT for i in range(10_000)]
---
> args = [sleep_time for i in range(10_000)]
2698a2707
> time.sleep(0.2) # give some tasks a chance to start
4631a4641,4663
> def test_filename(self):
> logger = multiprocessing.get_logger()
> original_level = logger.level
> try:
> logger.setLevel(util.DEBUG)
> stream = io.StringIO()
> handler = logging.StreamHandler(stream)
> logging_format = '[%(levelname)s] [%(filename)s] %(message)s'
> handler.setFormatter(logging.Formatter(logging_format))
> logger.addHandler(handler)
> logger.info('1')
> util.info('2')
> logger.debug('3')
> filename = os.path.basename(__file__)
> log_record = stream.getvalue()
> self.assertIn(f'[INFO] [{filename}] 1', log_record)
> self.assertIn(f'[INFO] [{filename}] 2', log_record)
> self.assertIn(f'[DEBUG] [{filename}] 3', log_record)
> finally:
> logger.setLevel(original_level)
> logger.removeHandler(handler)
> handler.close()
>

2 changes: 1 addition & 1 deletion py3.11/multiprocess/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, registry, address, authkey, serializer):
Listener, Client = listener_client[serializer]

# do authentication later
self.listener = Listener(address=address, backlog=16)
self.listener = Listener(address=address, backlog=128)
self.address = self.listener.address

self.id_to_obj = {'0': (None, ())}
Expand Down
54 changes: 30 additions & 24 deletions py3.11/multiprocess/popen_spawn_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,43 @@ def duplicate_for_child(self, handle):
return reduction.duplicate(handle, self.sentinel)

def wait(self, timeout=None):
if self.returncode is None:
if timeout is None:
msecs = _winapi.INFINITE
else:
msecs = max(0, int(timeout * 1000 + 0.5))

res = _winapi.WaitForSingleObject(int(self._handle), msecs)
if res == _winapi.WAIT_OBJECT_0:
code = _winapi.GetExitCodeProcess(self._handle)
if code == TERMINATE:
code = -signal.SIGTERM
self.returncode = code
if self.returncode is not None:
return self.returncode

if timeout is None:
msecs = _winapi.INFINITE
else:
msecs = max(0, int(timeout * 1000 + 0.5))

res = _winapi.WaitForSingleObject(int(self._handle), msecs)
if res == _winapi.WAIT_OBJECT_0:
code = _winapi.GetExitCodeProcess(self._handle)
if code == TERMINATE:
code = -signal.SIGTERM
self.returncode = code

return self.returncode

def poll(self):
return self.wait(timeout=0)

def terminate(self):
if self.returncode is None:
try:
_winapi.TerminateProcess(int(self._handle), TERMINATE)
except PermissionError:
# ERROR_ACCESS_DENIED (winerror 5) is received when the
# process already died.
code = _winapi.GetExitCodeProcess(int(self._handle))
if code == _winapi.STILL_ACTIVE:
raise
self.returncode = code
else:
self.returncode = -signal.SIGTERM
if self.returncode is not None:
return

try:
_winapi.TerminateProcess(int(self._handle), TERMINATE)
except PermissionError:
# ERROR_ACCESS_DENIED (winerror 5) is received when the
# process already died.
code = _winapi.GetExitCodeProcess(int(self._handle))
if code == _winapi.STILL_ACTIVE:
raise

# gh-113009: Don't set self.returncode. Even if GetExitCodeProcess()
# returns an exit code different than STILL_ACTIVE, the process can
# still be running. Only set self.returncode once WaitForSingleObject()
# returns WAIT_OBJECT_0 in wait().

kill = terminate

Expand Down
2 changes: 1 addition & 1 deletion py3.11/multiprocess/resource_sharer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _start(self):
from .connection import Listener
assert self._listener is None, "Already have Listener"
util.debug('starting listener and thread for sending handles')
self._listener = Listener(authkey=process.current_process().authkey)
self._listener = Listener(authkey=process.current_process().authkey, backlog=128)
self._address = self._listener.address
t = threading.Thread(target=self._serve)
t.daemon = True
Expand Down
34 changes: 33 additions & 1 deletion py3.11/multiprocess/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2702,9 +2702,18 @@ def test_make_pool(self):

def test_terminate(self):
# Simulate slow tasks which take "forever" to complete
sleep_time = support.LONG_TIMEOUT

if self.TYPE == 'threads':
# Thread pool workers can't be forced to quit, so if the first
# task starts early enough, we will end up waiting for it.
# Sleep for a shorter time, so the test doesn't block.
sleep_time = 1

p = self.Pool(3)
args = [support.LONG_TIMEOUT for i in range(10_000)]
args = [sleep_time for i in range(10_000)]
result = p.map_async(time.sleep, args, chunksize=1)
time.sleep(0.2) # give some tasks a chance to start
p.terminate()
p.join()

Expand Down Expand Up @@ -4654,6 +4663,29 @@ def test_level(self):
root_logger.setLevel(root_level)
logger.setLevel(level=LOG_LEVEL)

def test_filename(self):
logger = multiprocessing.get_logger()
original_level = logger.level
try:
logger.setLevel(util.DEBUG)
stream = io.StringIO()
handler = logging.StreamHandler(stream)
logging_format = '[%(levelname)s] [%(filename)s] %(message)s'
handler.setFormatter(logging.Formatter(logging_format))
logger.addHandler(handler)
logger.info('1')
util.info('2')
logger.debug('3')
filename = os.path.basename(__file__)
log_record = stream.getvalue()
self.assertIn(f'[INFO] [{filename}] 1', log_record)
self.assertIn(f'[INFO] [{filename}] 2', log_record)
self.assertIn(f'[DEBUG] [{filename}] 3', log_record)
finally:
logger.setLevel(original_level)
logger.removeHandler(handler)
handler.close()


# class _TestLoggingProcessName(BaseTestCase):
#
Expand Down
13 changes: 8 additions & 5 deletions py3.11/multiprocess/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@

def sub_debug(msg, *args):
if _logger:
_logger.log(SUBDEBUG, msg, *args)
_logger.log(SUBDEBUG, msg, *args, stacklevel=2)

def debug(msg, *args):
if _logger:
_logger.log(DEBUG, msg, *args)
_logger.log(DEBUG, msg, *args, stacklevel=2)

def info(msg, *args):
if _logger:
_logger.log(INFO, msg, *args)
_logger.log(INFO, msg, *args, stacklevel=2)

def sub_warning(msg, *args):
if _logger:
_logger.log(SUBWARNING, msg, *args)
_logger.log(SUBWARNING, msg, *args, stacklevel=2)

def get_logger():
'''
Expand Down Expand Up @@ -130,7 +130,10 @@ def is_abstract_socket_namespace(address):
#

def _remove_temp_dir(rmtree, tempdir):
rmtree(tempdir)
def onerror(func, path, err_info):
if not issubclass(err_info[0], FileNotFoundError):
raise
rmtree(tempdir, onerror=onerror)

current_process = process.current_process()
# current_process() can be None if the finalizer is called
Expand Down
Loading