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

Commit0193b83

Browse files
authored
Merge branch 'python:main' into main
2 parents19eaf85 +d07dcce commit0193b83

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

‎Lib/test/test_asyncio/test_tasks.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,28 @@ def test_get_context(self):
26882688
finally:
26892689
loop.close()
26902690

2691+
deftest_proper_refcounts(self):
2692+
# see: https://github.com/python/cpython/issues/126083
2693+
classBreak:
2694+
def__str__(self):
2695+
raiseRuntimeError("break")
2696+
2697+
obj=object()
2698+
initial_refcount=sys.getrefcount(obj)
2699+
2700+
coro=coroutine_function()
2701+
loop=asyncio.new_event_loop()
2702+
task=asyncio.Task.__new__(asyncio.Task)
2703+
2704+
for_inrange(5):
2705+
withself.assertRaisesRegex(RuntimeError,'break'):
2706+
task.__init__(coro,loop=loop,context=obj,name=Break())
2707+
2708+
coro.close()
2709+
deltask
2710+
2711+
self.assertEqual(sys.getrefcount(obj),initial_refcount)
2712+
26912713

26922714
defadd_subclass_tests(cls):
26932715
BaseTask=cls.Task
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a reference leak in:class:`asyncio.Task` objects when reinitializing the same object with a non-``None`` context. Patch by Nico Posada.

‎Modules/_asynciomodule.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
21202120
return-1;
21212121
}
21222122
}else {
2123-
self->task_context=Py_NewRef(context);
2123+
Py_XSETREF(self->task_context,Py_NewRef(context));
21242124
}
21252125

21262126
Py_CLEAR(self->task_fut_waiter);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp