classification
Title: webbrowser creates zombi processes in the background mode
Type: Stage:
Components: Versions: Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brendan-donegan, haypo, martin.panter
Priority: normal Keywords:

Created on 2016-05-20 12:23 by haypo, last changed 2016-12-15 15:33 by brendan-donegan.

Messages (4)
msg265939 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-05-20 12:23
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 #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 #27068 "Add a detach() method to subprocess.Popen", but I don't think that it is directly related to background processes run by webbrowser.
msg265944 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-05-20 13:33
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.
msg265945 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-20 14:07
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 won’t help. Don’t we want the opposite?
msg283326 - (view) Author: Brendan Donegan (brendan-donegan) * Date: 2016-12-15 15:33
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
History
Date User Action Args
2016-12-15 15:33:58brendan-donegansetnosy: + brendan-donegan
messages: + msg283326
2016-05-20 14:07:35martin.pantersetmessages: + msg265945
2016-05-20 13:33:10hayposetmessages: + msg265944
2016-05-20 12:23:17haypocreate