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

webbrowser creates zombi processes in the background mode #71256

Closed
vstinner opened this issue May 20, 2016 · 7 comments
Closed

webbrowser creates zombi processes in the background mode #71256

vstinner opened this issue May 20, 2016 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes

Comments

@vstinner
Copy link
Member

BPO 27069
Nosy @vstinner, @vadmium, @serhiy-storchaka, @kernc, @brendan-donegan

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 = <Date 2021-09-21.22:15:08.582>
created_at = <Date 2016-05-20.12:23:17.439>
labels = ['3.7', '3.8', '3.9']
title = 'webbrowser creates zombi processes in the background mode'
updated_at = <Date 2021-09-21.22:15:08.581>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2021-09-21.22:15:08.581>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2021-09-21.22:15:08.582>
closer = 'vstinner'
components = []
creation = <Date 2016-05-20.12:23:17.439>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 27069
keywords = []
message_count = 7.0
messages = ['265939', '265944', '265945', '283326', '313085', '314015', '402388']
nosy_count = 5.0
nosy_names = ['vstinner', 'martin.panter', 'serhiy.storchaka', 'kernc', 'brendan-donegan']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue27069'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9']

@vstinner
Copy link
Member Author

The webbrowser opens almost all browsers in background mode, it looks like only Elinks is not opened in this mode.

Problem: the webbrowser doesn't read the exit status of the browser, and so create zombi process. On Python 3.6, the subprocess module now emits a ResourceWarning in this case (issue bpo-26741).

For example, the following script shows a zombi process ("<defunc>"):
---

import webbrowser, os

b = webbrowser.get("firefox")
b.open("https://bugs.python.org/issue26741")
b = None

os.system("ps ax|grep firefox")
input("press ENTER when firefox exited")
os.system("ps ax|grep firefox")

I guess that Python should use os.fork() somehow to fix this issue.

Another option is to hack the Popen object to not display the warning, but I don't think that it's a safe option.

See also the issue bpo-27068 "Add a detach() method to subprocess.Popen", but I don't think that it is directly related to background processes run by webbrowser.

@vstinner
Copy link
Member Author

I checked how "xdg-open http://www.python.org/" works. It looks like the command works as webbrowser: create a child process "firefox URL", but then it waits until the command completes.

In fact, "firefox URL" exits quickly. So we can try "background = False" for firefox. Well, at least with my Firefox 46.0.1.

@vadmium
Copy link
Member

vadmium commented May 20, 2016

I think the Firefox command will exit immediately if it just signals an existing Firefox process and window, but becomes the main Firefox process if there isn’t already one running.

Background = False sounds like it wont help. Dont we want the opposite?

@brendan-donegan
Copy link
Mannequin

brendan-donegan mannequin commented Dec 15, 2016

This appears to be Firefox specific? At least:

b = webbrowser.get("chromium-browser")
b.open("https://bugs.python.org/issue26741")

returns simply:

True

With no exception

@serhiy-storchaka
Copy link
Member

Isn't this a duplicate of bpo-5993?

@vadmium
Copy link
Member

vadmium commented Mar 17, 2018

It does look similar. They probably could be merged. The main difference is in bpo-5993 Eivind suggested to somehow use a “wait” system call, while here Victor suggested “fork” (perhaps to orphan a grandchild process?).

@kernc kernc mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Jan 11, 2020
@vstinner
Copy link
Member Author

Python 3.6 was released 5 years ago. Nobody complained about ResourceWarning. While it would be nice to fix the issue, nobody managed to write a fix in 5 years and this issue has no activity for 3 years. I close the issue.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
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 only security fixes 3.9 only security fixes
Projects
None yet
Development

No branches or pull requests

3 participants