tornadoweb / tornadoweb/tornado

`Subprocess.wait_for_exit` never resolves if process terminated before it is called

Open
#3,364 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

process
Dominant language
Python
Stars
22.2k
Forks
5.6k
Avg merge
3h 42m
Merged PRs (30d)
16

Description

The wait_for_exit method eventually calls os.waitpid, which throws a ChildProcessError if no process with the specified pid exists. This exception is caught, the function just returns, and the Future never resolves.

if __name__ == '__main__':
    import asyncio
    from tornado.process import Subprocess

    async def f():
        p = Subprocess("ls")
        p.proc.wait()
        return await p.wait_for_exit()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(f())

https://github.com/tornadoweb/tornado/blob/65a9e48f8ce645f104e3e0aa772222e70b0376d9/tornado/process.py#L348

Instead, the process could be retrieved from the _waiting dict and the return code could be accessed from the object directly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tornado/process.py at Subprocess.wait_for_exit and inspect how os.waitpid errors are handled and how the _waiting dictionary stores processes. Reproduce the example, then make the Future resolve when the process terminated before wait_for_exit was called, using the available return code.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.