Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
fixing zombie daemons
Browse files Browse the repository at this point in the history
  • Loading branch information
vegitron committed Jan 23, 2017
1 parent 38f8dd0 commit e65768a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion sqlshare_rest/util/dataset_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def start_upload(upload, background=True):
from django.db import connection
connection.close()

if os.fork():
pid1 = os.fork()
if pid1:
os.waitpid(pid1, 0)
# This is the main process
return

Expand Down
14 changes: 3 additions & 11 deletions sqlshare_rest/util/query_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def start_query(query, background=True):
from django.db import connection
connection.close()

if os.fork():
pid1 = os.fork()
if pid1:
os.waitpid(pid1, 0)
# This is the main process
return

Expand All @@ -51,16 +53,6 @@ def start_query(query, background=True):
# Double fork the daemon
sys.exit(0)

# Close stdin/out/err
sys.stdin.flush()
sys.stdout.flush()
sys.stderr.flush()
null = os.open(os.devnull, os.O_RDWR)
os.dup2(null, sys.stdin.fileno())
os.dup2(null, sys.stdout.fileno())
os.dup2(null, sys.stderr.fileno())
os.close(null)

try:
process_query(query_id)
except Exception as ex:
Expand Down
4 changes: 3 additions & 1 deletion sqlshare_rest/util/snapshot_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def start_snapshot(snapshot, background=True):
from django.db import connection
connection.close()

if os.fork():
pid1 = os.fork()
if pid1:
os.waitpid(pid1, 0)
# This is the main process
return

Expand Down

0 comments on commit e65768a

Please sign in to comment.