Skip to content

Commit

Permalink
Merge pull request #8 from PodgroupConnectivity/disconnect
Browse files Browse the repository at this point in the history
Disconnect killing children processes
  • Loading branch information
COUR4G3 authored Aug 9, 2018
2 parents 1759018 + bd8ba61 commit 7cd990b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pppd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def __init__(self, *args, **kwargs):
commands.extend(args)
commands.append('nodetach')

self.proc = Popen(commands, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
self.proc = Popen(commands,
stdout=PIPE,
stderr=STDOUT,
universal_newlines=True,
preexec_fn=os.setsid)

# set stdout to non-blocking
fd = self.proc.stdout.fileno()
Expand Down Expand Up @@ -136,5 +140,9 @@ def disconnect(self):
except PPPConnectionError:
return

self.proc.send_signal(signal.SIGHUP)
self.proc.wait()
# Send the signal to all the processes in group
# Based on stackoverlfow:
# https://stackoverflow.com/questions/4789837/how-to-terminate-a-python-subprocess-launched-with-shell-true/
os.killpg(os.getpgid(self.proc.pid), signal.SIGHUP)
os.killpg(os.getpgid(self.proc.pid), signal.SIGTERM)

0 comments on commit 7cd990b

Please sign in to comment.