Commit 2bc8cca7 authored by drallensmith's avatar drallensmith

Merge branch 'master' into mark_player_better - avoid rebase

parents d0ae33f4 be18fc75
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import print_function from __future__ import print_function
import subprocess, os, time, numpy, sys import atexit
import numpy
import os
import time
import signal
import subprocess
import sys
# Global list of all/essential running processes # Global list of all/essential running processes
processes, necProcesses = [], [] processes, necProcesses = [], []
...@@ -12,6 +18,16 @@ SERVER_BIN = 'rcssserver' ...@@ -12,6 +18,16 @@ SERVER_BIN = 'rcssserver'
# Command to run the monitor. Edit as needed; ditto to the above re directories. # Command to run the monitor. Edit as needed; ditto to the above re directories.
MONITOR_BIN = 'soccerwindow2' MONITOR_BIN = 'soccerwindow2'
def cleanup():
"""Cleanup even if doing SystemExit, as with term."""
for p in reversed(processes):
p.terminate()
time.sleep(0.1)
p.kill()
def term(received_signal, ignored_stack):
sys.exit("Signal {0!r} received; exiting".format(received_signal))
def launch(cmd, name = 'Unknown', necessary = True, suppressOutput = True): def launch(cmd, name = 'Unknown', necessary = True, suppressOutput = True):
"""Launch a process. """Launch a process.
...@@ -22,8 +38,8 @@ def launch(cmd, name = 'Unknown', necessary = True, suppressOutput = True): ...@@ -22,8 +38,8 @@ def launch(cmd, name = 'Unknown', necessary = True, suppressOutput = True):
""" """
kwargs = {} kwargs = {}
if suppressOutput: if suppressOutput:
kwargs = {'stdout': open('/dev/null', 'w'), kwargs = {'stdout': open(os.devnull, 'w'),
'stderr': open('/dev/null', 'w')} 'stderr': open(os.devnull, 'w')}
try: try:
p = subprocess.Popen(cmd.split(' '), shell = False, **kwargs) p = subprocess.Popen(cmd.split(' '), shell = False, **kwargs)
except (IOError, OSError): except (IOError, OSError):
...@@ -69,6 +85,13 @@ def main(args): ...@@ -69,6 +85,13 @@ def main(args):
args.min_ball_x, args.max_ball_x, args.messageSize, args.min_ball_x, args.max_ball_x, args.messageSize,
args.verbose) args.verbose)
try:
signal.signal(signal.SIGTERM, term)
except (ValueError, AttributeError):
print("Not able to catch sigterm")
atexit.register(cleanup)
try: try:
# Launch the Server # Launch the Server
server = launch(serverCommand + serverOptions, name='server', server = launch(serverCommand + serverOptions, name='server',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment