Skip to content

all deprecation warnings are disabled for the whole process while new unix asyncio subprocesses are created #98327

Description

@graingert

on python3.10 the following prints:

python3.10 demo.py /home/graingert/projects/cpython/demo.py:40: DeprecationWarning: demo warning
warnings.warn("demo warning", DeprecationWarning)
/home/graingert/projects/cpython/demo.py:48: DeprecationWarning: demo warning2
warnings.warn("demo warning2", DeprecationWarning)

but on python main it prints:

./python demo.py /home/graingert/projects/cpython/demo.py:40: DeprecationWarning: demo warning
warnings.warn("demo warning", DeprecationWarning)
importsysimportthreadingimportasyncioimportconcurrent.futuresimportwarningsasyncdefacreate_process_then_sleep(started_event, stop_event):
event=asyncio.Event()
asyncdefcreate_process():
loop=asyncio.get_running_loop()
loop.call_soon(event.set)
proc=awaitasyncio.create_subprocess_exec(
sys.executable,
"-c",
"print('hello')",
stdin=None,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
)
awaitproc.communicate()
asyncdefsleep():
awaitevent.wait()
started_event.set()
stop_event.wait()
awaitasyncio.gather(create_process(), sleep())
defcreate_process_then_sleep(*args, **kwargs):
asyncio.run(acreate_process_then_sleep(*args, **kwargs))
defmain():
withconcurrent.futures.ThreadPoolExecutor() astpe:
stop_event=threading.Event()
started_event=threading.Event()
warnings.warn("demo warning", DeprecationWarning)
fut=tpe.submit(
create_process_then_sleep,
started_event=started_event,
stop_event=stop_event,
)
try:
started_event.wait()
warnings.warn("demo warning2", DeprecationWarning)
finally:
stop_event.set()
fut.result()
if__name__=="__main__":
sys.exit(main())

Originally posted by @graingert in #98215 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions