Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio subprocesses allow pids to be reaped, different behavior than regular subprocesses #84259

Closed
JustinLebar mannequin opened this issue Mar 26, 2020 · 3 comments
Closed
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@JustinLebar
Copy link
Mannequin

JustinLebar mannequin commented Mar 26, 2020

BPO 40078
Nosy @asvetlov, @1st1, @c-lewin

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-03-26.17:06:33.546>
labels = ['3.8', 'type-bug', '3.7', '3.9', 'expert-asyncio']
title = 'asyncio subprocesses allow pids to be reaped, different behavior than regular subprocesses'
updated_at = <Date 2020-04-19.03:14:10.157>
user = 'https://bugs.python.org/JustinLebar'

bugs.python.org fields:

activity = <Date 2020-04-19.03:14:10.157>
actor = 'c-lewin'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['asyncio']
creation = <Date 2020-03-26.17:06:33.546>
creator = 'Justin.Lebar'
dependencies = []
files = []
hgrepos = []
issue_num = 40078
keywords = []
message_count = 2.0
messages = ['365095', '366752']
nosy_count = 4.0
nosy_names = ['asvetlov', 'Justin.Lebar', 'yselivanov', 'c-lewin']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue40078'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

@JustinLebar
Copy link
Mannequin Author

JustinLebar mannequin commented Mar 26, 2020

From https://bugs.python.org/issue1187312 about regular subprocesses:

So as long as the application keeps a reference to the
subprocess object, it can wait for it; auto-reaping only
starts when the last reference was dropped [in Popen.__del__].

asyncio subprocesses seem to behave differently. When we notice the process has exited in BaseSubprocessTransport._process_exited, we call _try_finish(), which -- if all pipes are closed -- calls _call_connection_lost and sets self._proc to None.

At this point, my understanding is that once self._proc is GC'ed, we'll run Popen.__del__ and may reap the pid.

I would expect asyncio subprocesses to behave the same way as regular Popen objects wrt pid reaping.

@JustinLebar JustinLebar mannequin added topic-asyncio 3.9 only security fixes type-bug An unexpected behavior, bug, or error 3.7 (EOL) end of life 3.8 (EOL) end of life labels Mar 26, 2020
@c-lewin
Copy link
Mannequin

c-lewin mannequin commented Apr 19, 2020

Very first time engaging in such a forum. Apologies is advance if I am doing it wrong!

Observation: ps -ef shows "Defunct" process until calling script terminates

Scenario: equivalent test scripts in BASH, Python 2.7 and 3.6 that:

  1. Start a ping
  2. SIGTERM (kill -15) the associated PID
  3. wait for a user input (hence stopping the script terminating)

I tried P.Open and threading but behaviour is same.

BASH script does not show any "defunct" process.

Is this "Child Reaping" the cause of this observed behaviour?

Problem comes when the Parent script is required to run constantly (server type scenario) as the "defunct" processes will presumably eventually consume all system resources?

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@ezio-melotti ezio-melotti moved this to Todo in asyncio Jul 17, 2022
@kumaraditya303
Copy link
Contributor

Duplicate of #87744

This is basically same as #87744, both will be taken care of when rewriting subprocess handling in 3.14 without child watchers.

@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

1 participant