Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1239] make play stop wait for java process to finish #1257

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework/pym/play/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def run(app, args):
try:
process = subprocess.Popen (java_cmd, env=os.environ)
signal.signal(signal.SIGTERM, handle_sigterm)
signal.signal(signal.SIGINT, handle_sigint)
return_code = process.wait()
signal.signal(signal.SIGINT, handle_sigint)
if 0 != return_code:
sys.exit(return_code)
except OSError:
Expand Down
22 changes: 21 additions & 1 deletion framework/pym/play/commands/daemon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import errno
import os
import os.path
import signal
import subprocess
import time

Expand Down Expand Up @@ -160,13 +162,31 @@ def kill(pid):
print "~ Process with PID %s terminated" % pid
else:
try:
os.kill(int(pid), 15)
_terminate_unix_process_if_exists(int(pid))
except OSError:
print "~ Play was not running (Process id %s not found)" % pid
print "~"
sys.exit(-1)


def _terminate_unix_process_if_exists(pid_to_terminate):
os.kill(pid_to_terminate, signal.SIGTERM)

try:
os.waitpid(pid_to_terminate, 0)
except OSError as error:

# If the child process managed to terminate itself before Play started
# waiting for it, that's OK.
if error.errno != errno.ECHILD:
message_format = (
"~ Failed to wait for process {} to finish after requesting "
"termination\n~")
message = message_format.format(pid_to_terminate)
print(message)



def process_running(pid):
if os.name == 'nt':
return process_running_nt(pid)
Expand Down