Example #1
0
def test_command_async():
    t_launch = time.time()
    t_sleep = t_launch
    proc = osext.run_command_async('sleep 1')
    t_launch = time.time() - t_launch

    proc.wait()
    t_sleep = time.time() - t_sleep

    # Now check the timings
    assert t_launch < 1
    assert t_sleep >= 1
Example #2
0
    def submit(self, job):
        # Run from the absolute path
        f_stdout = open(job.stdout, 'w+')
        f_stderr = open(job.stderr, 'w+')

        # The new process starts also a new session (session leader), so that
        # we can later kill any other processes that this might spawn by just
        # killing this one.
        proc = osext.run_command_async(os.path.abspath(job.script_filename),
                                       stdout=f_stdout,
                                       stderr=f_stderr,
                                       start_new_session=True)

        # Update job info
        job._jobid = proc.pid
        job._nodelist = [socket.gethostname()]
        job._proc = proc
        job._f_stdout = f_stdout
        job._f_stderr = f_stderr
        job._submit_time = time.time()
        job._state = 'RUNNING'
Example #3
0
def test_trap_signal(script_file):
    with shell.generate_script(script_file, trap_signals=True) as gen:
        gen.write('sleep 10')
        gen.write('echo hello')

    f_stdout = tempfile.NamedTemporaryFile(mode='w+', delete=False)
    proc = osext.run_command_async(str(script_file), stdout=f_stdout,
                                   start_new_session=True)

    # Yield for some time to allow the script to start
    time.sleep(1)

    # We kill the whole spawned process group (we are launching a shell)
    os.killpg(proc.pid, 15)
    proc.wait()

    f_stdout.flush()
    f_stdout.seek(0)
    stdout = f_stdout.read()
    assert 'hello' not in stdout
    assert 143 == proc.returncode
    assert '-reframe: script caught signal: 15' in stdout