Opened 17 years ago
Closed 17 years ago
#6175 closed (fixed)
become_daemon should use os._exit instead of sys.exit
Reported by: | Owned by: | Leo Shklovskii | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | daemon, daemonize, become_daemon, segfault | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
django.utils.daemonize.become_daemon forks then uses sys.exit(0) instead of os._exit(0), which can cause some nasty issues. os._exit is the correct way to exit after forking in Python, as os._exit avoids calling Python cleanup functions which may cause issues such as segfaults.
See http://docs.python.org/lib/os-process.html for details on os._exit().
Attachments (2)
Change History (10)
by , 17 years ago
Attachment: | daemon.patch added |
---|
comment:1 by , 17 years ago
Summary: | become_daemon should use os._exit instead of sys.exit → [patch] become_daemon should use os._exit instead of sys.exit |
---|
comment:2 by , 17 years ago
Summary: | [patch] become_daemon should use os._exit instead of sys.exit → become_daemon should use os._exit instead of sys.exit |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:3 by , 17 years ago
Triage Stage: | Design decision needed → Accepted |
---|
This is only half right. The main parent should call sys.exit(), since it can be cleaned up normally; it's a normal short-lived process. The children should generally call os._exit() to avoid double cleanups via atexit() paths.
So I believe the first change is wrong and the second change is right, but I need to do some re-reading to confirm this.
by , 17 years ago
Attachment: | 6175_second_patch.diff added |
---|
comment:4 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Malcolm, you're right. The first exit() call is in the parent so it should stay exit(). The second call is in the first child, so _exit() is more appropriate. I've attached a patch only to correct the second one.
comment:5 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:6 by , 17 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Malcolm wrote:
So I believe the first change is wrong and the second change is right, but I need to do some re-reading to confirm this.
and Leo wrote:
Malcolm, you're right. The first exit() call is in the parent so it should stay exit().
But the patch actually committed changes both calls. Are you sure that's correct?
comment:7 by , 17 years ago
No it didn't. Have a look at the line numbers affected. The patch I committed was a variant on the two attached to these tickets and fixed a place that was overlooked in both those patches.
comment:8 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Ah, I see. Glad to see it wasn't a mistake after all.
Pushing to a design decision as it's over my head :)