Commit ed46a08d authored by Marco Buttu's avatar Marco Buttu
Browse files

Fix #152: send a signal.SIGTERM

I executed the process in the shell and used a process group to send
a signal to all the process in the groups.
I attached a session id to the parent process of the spawned/child
processes, which is a shell in this case. This will make it the group
leader of the processes.  So now, when a signal is sent to the process
group leader, it's transmitted to all of the child processes of this group.
parent 203e66f1
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
import os
import sys
import time
import signal
import unittest
import subprocess


def run(test_case):
    # Use the simulators and the testing CDB
    server_name = 'srt-mscu' if test_case.telescope == 'SRT' else ''
    if not server_name:
        sys.exit(0) 

    FNULL = open(os.devnull, 'w')
    try:
        subprocess.Popen(['%s-sim' % server_name, 'start'], stdout=FNULL, stderr=FNULL)
        FNULL = open(os.devnull, 'w')
        process = subprocess.Popen(
            '%s-sim start' % server_name, stdout=FNULL, stderr=FNULL,
            shell=True, preexec_fn=os.setsid)
        time.sleep(1) # Give the server the time to start
        suite = unittest.TestSuite()
        tests = unittest.TestLoader().loadTestsFromTestCase(test_case)
@@ -20,5 +24,6 @@ def run(test_case):
        print 'Running the tests using the antenna simulators...'
        unittest.TextTestRunner(verbosity=2).run(suite)
    finally:
        subprocess.Popen(['%s-sim' % server_name, 'stop'], stdout=FNULL, stderr=FNULL)
        os.killpg(os.getpgid(process.pid), signal.SIGTERM) 
        time.sleep(2) # Give the server the time to stop
        FNULL.close()