Skip to content

Commit

Permalink
Handle sigterm gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur committed Aug 18, 2011
1 parent f94a3fc commit 331fc55
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion framework/pym/play/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import urllib2
import webbrowser
import time
import signal

from play.utils import *

Expand Down Expand Up @@ -119,14 +120,25 @@ def new(app, args, env, cmdloader=None):
print "~ Have fun!"
print "~"

process = None

def handle_sigterm(signum, frame):
global process
if 'process' in globals():
process.terminate()
sys.exit(0)

def run(app, args):
global process
app.check()

print "~ Ctrl+C to stop"
print "~ "
java_cmd = app.java_cmd(args)
try:
subprocess.call(java_cmd, env=os.environ)
process = subprocess.Popen (java_cmd, env=os.environ)
signal.signal(signal.SIGTERM, handle_sigterm)
process.wait()
except OSError:
print "Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly (the java executable should reside at JAVA_HOME/bin/java). "
sys.exit(-1)
Expand Down

0 comments on commit 331fc55

Please sign in to comment.