Skip to content

Commit f6e4362

Browse files
committed
Fix test_task_factory for Python 3.11 compatibility
The eager_start parameter for asyncio.Task was introduced in Python 3.12. Use version check to fall back to loop parameter on Python 3.10-3.11. Also include loop parameter in Python 3.12+ for proper task association.
1 parent 6650811 commit f6e4362

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

priv/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def task_factory(loop, coro):
479479
# Create task compatible with all Python versions
480480
if sys.version_info >= (3, 12):
481481
# Python 3.12+: use eager_start=False to opt out of eager execution
482-
return asyncio.Task(coro, eager_start=False)
482+
return asyncio.Task(coro, loop=loop, eager_start=False)
483483
else:
484484
# Python 3.10-3.11: loop parameter deprecated but still works
485485
return asyncio.Task(coro, loop=loop)

src/py_event_loop.erl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,14 @@ spawn_task(Module, Func, Args, Kwargs) ->
234234
%% The namespace is automatically cleaned up when the process exits.
235235
%%
236236
%% Example:
237-
%% ok = py_event_loop:exec(<<"
237+
%% <pre>
238+
%% ok = py_event_loop:exec(&lt;&lt;"
238239
%% async def my_async_func(x):
239240
%% return x * 2
240-
%% ">>),
241-
%% Ref = py_event_loop:create_task('__main__', my_async_func, [21]),
242-
%% {ok, 42} = py_event_loop:await(Ref)
241+
%% "&gt;&gt;),
242+
%% Ref = py_event_loop:create_task('__main__', my_async_func, [21]),
243+
%% {ok, 42} = py_event_loop:await(Ref)
244+
%% </pre>
243245
-spec exec(Code :: binary() | iolist()) -> ok | {error, term()}.
244246
exec(Code) ->
245247
{ok, LoopRef} = get_loop(),
@@ -254,9 +256,11 @@ exec(LoopRef, Code) ->
254256
%% Returns the result of evaluating the expression.
255257
%%
256258
%% Example:
257-
%% ok = py_event_loop:exec(<<"x = 42">>),
258-
%% {ok, 42} = py_event_loop:eval(<<"x">>),
259-
%% {ok, 84} = py_event_loop:eval(<<"x * 2">>)
259+
%% <pre>
260+
%% ok = py_event_loop:exec(&lt;&lt;"x = 42"&gt;&gt;),
261+
%% {ok, 42} = py_event_loop:eval(&lt;&lt;"x"&gt;&gt;),
262+
%% {ok, 84} = py_event_loop:eval(&lt;&lt;"x * 2"&gt;&gt;)
263+
%% </pre>
260264
-spec eval(Expr :: binary() | iolist()) -> {ok, term()} | {error, term()}.
261265
eval(Expr) ->
262266
{ok, LoopRef} = get_loop(),

0 commit comments

Comments
 (0)