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

Commit

Permalink
Merge pull request #17 from mkiwala/pidfile
Browse files Browse the repository at this point in the history
Add --pidfile option to devserver
  • Loading branch information
davidlmorton committed Feb 6, 2015
2 parents 1da6afd + ed87aaf commit b549b14
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ptero_common/devserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

honcho_process = None
child_pids = set()
_pidfile = None


# This is from a stackoverflow answer:
Expand All @@ -31,6 +32,8 @@ def shutdown():
if signal_processes(child_pids, signal.SIGINT):
time.sleep(3)
signal_processes(child_pids, signal.SIGKILL)
if _pidfile is not None:
os.remove(_pidfile)


def signal_processes(pids, sig):
Expand Down Expand Up @@ -90,9 +93,20 @@ def setup_signal_handlers():
signal.signal(signal.SIGTERM, log_and_cleanup)


def run(logdir, procfile_path, workers):
def write_pidfile(pidfile):
global _pidfile
if pidfile is not None:
mkdir_p(os.path.dirname(pidfile))
with open(pidfile, 'w') as ofile:
ofile.write(str(os.getpid()))
_pidfile = pidfile


def run(logdir, procfile_path, workers, pidfile):
global honcho_process

write_pidfile(pidfile)

setup_signal_handlers()

if (logdir == '-'):
Expand Down

0 comments on commit b549b14

Please sign in to comment.