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

Appearance settings

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

Copy link
Copy link
@graingert

Description

@graingert
Issue body actions

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)
import sys
import threading
import asyncio
import concurrent.futures
import warnings


async def acreate_process_then_sleep(started_event, stop_event):
    event = asyncio.Event()

    async def create_process():
        loop = asyncio.get_running_loop()
        loop.call_soon(event.set)
        proc = await asyncio.create_subprocess_exec(
            sys.executable,
            "-c",
            "print('hello')",
            stdin=None,
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.STDOUT,
        )
        await proc.communicate()

    async def sleep():
        await event.wait()
        started_event.set()
        stop_event.wait()

    await asyncio.gather(create_process(), sleep())


def create_process_then_sleep(*args, **kwargs):
    asyncio.run(acreate_process_then_sleep(*args, **kwargs))


def main():
    with concurrent.futures.ThreadPoolExecutor() as tpe:
        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)

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    Status
    Done
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.