Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit140770f

Browse files
authored
Merge branch 'main' into setobject-note
2 parentsed90b66 +2dc9463 commit140770f

File tree

12 files changed

+95
-48
lines changed

12 files changed

+95
-48
lines changed

‎Lib/asyncio/tasks.py‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from .importexceptions
2626
from .importfutures
2727
from .importtimeouts
28-
from .coroutinesimport_is_coroutine
2928

3029
# Helper to generate new task names
3130
# This uses itertools.count() instead of a "+= 1" operation because the latter
@@ -635,11 +634,14 @@ def ensure_future(coro_or_future, *, loop=None):
635634
raiseValueError('The future belongs to a different loop than '
636635
'the one specified as the loop argument')
637636
returncoro_or_future
638-
called_wrap_awaitable=False
637+
should_close=True
639638
ifnotcoroutines.iscoroutine(coro_or_future):
640639
ifinspect.isawaitable(coro_or_future):
640+
asyncdef_wrap_awaitable(awaitable):
641+
returnawaitawaitable
642+
641643
coro_or_future=_wrap_awaitable(coro_or_future)
642-
called_wrap_awaitable=True
644+
should_close=False
643645
else:
644646
raiseTypeError('An asyncio.Future, a coroutine or an awaitable '
645647
'is required')
@@ -649,23 +651,11 @@ def ensure_future(coro_or_future, *, loop=None):
649651
try:
650652
returnloop.create_task(coro_or_future)
651653
exceptRuntimeError:
652-
ifnotcalled_wrap_awaitable:
654+
ifshould_close:
653655
coro_or_future.close()
654656
raise
655657

656658

657-
@types.coroutine
658-
def_wrap_awaitable(awaitable):
659-
"""Helper for asyncio.ensure_future().
660-
661-
Wraps awaitable (an object with __await__) into a coroutine
662-
that will later be wrapped in a Task by ensure_future().
663-
"""
664-
return (yieldfromawaitable.__await__())
665-
666-
_wrap_awaitable._is_coroutine=_is_coroutine
667-
668-
669659
class_GatheringFuture(futures.Future):
670660
"""Helper for gather().
671661

‎Lib/concurrent/futures/process.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ def run(self):
366366
ifself.is_shutting_down():
367367
self.flag_executor_shutting_down()
368368

369+
# When only canceled futures remain in pending_work_items, our
370+
# next call to wait_result_broken_or_wakeup would hang forever.
371+
# This makes sure we have some running futures or none at all.
372+
self.add_call_item_to_queue()
373+
369374
# Since no new work items can be added, it is safe to shutdown
370375
# this thread if there are no pending work items.
371376
ifnotself.pending_work_items:

‎Lib/test/test_asyncio/test_tasks.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
importre
99
importsys
1010
importtraceback
11+
importtypes
1112
importunittest
1213
fromunittestimportmock
1314
fromtypesimportGenericAlias
@@ -274,6 +275,20 @@ async def coro():
274275
loop.run_until_complete(fut)
275276
self.assertEqual(fut.result(),'ok')
276277

278+
deftest_ensure_future_task_awaitable(self):
279+
classAw:
280+
def__await__(self):
281+
returnasyncio.sleep(0,result='ok').__await__()
282+
283+
loop=asyncio.new_event_loop()
284+
self.set_event_loop(loop)
285+
task=asyncio.ensure_future(Aw(),loop=loop)
286+
loop.run_until_complete(task)
287+
self.assertTrue(task.done())
288+
self.assertEqual(task.result(),'ok')
289+
self.assertIsInstance(task.get_coro(),types.CoroutineType)
290+
loop.close()
291+
277292
deftest_ensure_future_neither(self):
278293
withself.assertRaises(TypeError):
279294
asyncio.ensure_future('ok')

‎Lib/test/test_concurrent_futures.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
fromlogging.handlersimportQueueHandler
1515
importos
1616
importqueue
17+
importsignal
1718
importsys
1819
importthreading
1920
importtime
@@ -397,6 +398,33 @@ def test_hang_gh83386(self):
397398
self.assertFalse(err)
398399
self.assertEqual(out.strip(),b"apple")
399400

401+
deftest_hang_gh94440(self):
402+
"""shutdown(wait=True) doesn't hang when a future was submitted and
403+
quickly canceled right before shutdown.
404+
405+
See https://github.com/python/cpython/issues/94440.
406+
"""
407+
ifnothasattr(signal,'alarm'):
408+
raiseunittest.SkipTest(
409+
"Tested platform does not support the alarm signal")
410+
411+
deftimeout(_signum,_frame):
412+
raiseRuntimeError("timed out waiting for shutdown")
413+
414+
kwargs= {}
415+
ifgetattr(self,'ctx',None):
416+
kwargs['mp_context']=self.get_context()
417+
executor=self.executor_type(max_workers=1,**kwargs)
418+
executor.submit(int).result()
419+
old_handler=signal.signal(signal.SIGALRM,timeout)
420+
try:
421+
signal.alarm(5)
422+
executor.submit(int).cancel()
423+
executor.shutdown(wait=True)
424+
finally:
425+
signal.alarm(0)
426+
signal.signal(signal.SIGALRM,old_handler)
427+
400428

401429
classThreadPoolShutdownTest(ThreadPoolMixin,ExecutorShutdownTest,BaseTestCase):
402430
deftest_threads_terminate(self):

‎Lib/webbrowser.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,15 @@ def register_standard_browsers():
542542
# First try to use the default Windows browser
543543
register("windows-default",WindowsDefault)
544544

545-
# Detect some common Windows browsers, fallback to IE
546-
iexplore=os.path.join(os.environ.get("PROGRAMFILES","C:\\Program Files"),
547-
"Internet Explorer\\IEXPLORE.EXE")
545+
# Detect some common Windows browsers, fallback to Microsoft Edge
546+
# location in 64-bit Windows
547+
edge64=os.path.join(os.environ.get("PROGRAMFILES(x86)","C:\\Program Files (x86)"),
548+
"Microsoft\\Edge\\Application\\msedge.exe")
549+
# location in 32-bit Windows
550+
edge32=os.path.join(os.environ.get("PROGRAMFILES","C:\\Program Files"),
551+
"Microsoft\\Edge\\Application\\msedge.exe")
548552
forbrowserin ("firefox","firebird","seamonkey","mozilla",
549-
"netscape","opera",iexplore):
553+
"opera",edge64,edge32):
550554
ifshutil.which(browser):
551555
register(browser,None,BackgroundBrowser(browser))
552556
else:

‎Misc/ACKS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ Thomas Perl
13851385
Mathieu Perreault
13861386
Mark Perrego
13871387
Trevor Perrin
1388+
Yonatan Perry
13881389
Gabriel de Perthuis
13891390
Tim Peters
13901391
Benjamin Peterson
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a:mod:`concurrent.futures.process` bug where ``ProcessPoolExecutor`` shutdown
2+
could hang after a future has been quickly submitted and canceled.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:meth:`asyncio.Task.get_coro` now always returns a coroutine when wrapping an awaitable object. Patch by Kumar Aditya.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update:mod:`webbrowser` to fall back to Microsoft Edge instead of Internet Explorer.

‎Python/bltinmodule.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,9 +3098,6 @@ _PyBuiltin_Init(PyInterpreterState *interp)
30983098
}
30993099
Py_DECREF(debug);
31003100

3101-
/* m_copy of Py_None means it is copied some other way. */
3102-
builtinsmodule.m_base.m_copy=Py_NewRef(Py_None);
3103-
31043101
returnmod;
31053102
#undef ADD_TO_ALL
31063103
#undef SETBUILTIN

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp