Ignore:
Timestamp:
Mar 26, 2019, 11:15:49 AM (6 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b10f95, ae6b6cf
Parents:
5bf1f3e
Message:

No longer need to use popen and signal handling in test.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    r5bf1f3e r1bb2488  
    88import signal
    99import stat
     10import subprocess
    1011import sys
    1112import time
     
    2021
    2122# helper functions to run terminal commands
    22 def sh(cmd, print2stdout = True, input = None):
     23def sh(cmd, print2stdout = True, timeout = False, output = None, input = None):
    2324        # add input redirection if needed
    2425        if input and os.path.isfile(input):
    2526                cmd += " < %s" % input
     27
     28        # add output redirection if needed
     29        if output:
     30                cmd += " > %s" % output
    2631
    2732        # if this is a dry_run, only print the commands that would be ran
     
    3237        # otherwise create a pipe and run the desired command
    3338        else :
    34                 proc = Popen(cmd, stdout=None if print2stdout else PIPE, stderr=STDOUT, shell=True)
    35                 out, err = proc.communicate()
    36                 return proc.returncode, out
     39                proc = subprocess.run(
     40                        cmd,
     41                        stdout=None if print2stdout else PIPE,
     42                        stderr=STDOUT,
     43                        shell=True,
     44                        timeout=settings.timeout.single if timeout else None
     45                )
     46                return proc.returncode, proc.stdout
    3747
    3848def is_ascii(fname):
     
    128138    return None
    129139
    130 def run(exe, output, input):
    131         ret, _ = sh("timeout %d %s > %s 2>&1" % (settings.timeout.single, exe, output), input = input)
    132         return ret
    133 
    134140################################################################################
    135141#               file handling
     
    208214        return min( options.jobs, len(tests) ), force
    209215
    210 # setup a proper processor pool with correct signal handling
    211 def setup_pool(jobs):
    212         original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
    213         pool = multiprocessing.Pool(jobs)
    214         signal.signal(signal.SIGINT, original_sigint_handler)
    215 
    216         return pool
    217 
    218 # handle signals in scope
    219 class SignalHandling():
    220         def __enter__(self):
    221                 # enable signal handling
    222                 signal.signal(signal.SIGINT, signal.SIG_DFL)
    223 
    224         def __exit__(self, type, value, traceback):
    225                 # disable signal handling
    226                 signal.signal(signal.SIGINT, signal.SIG_IGN)
    227 
    228 
    229216# enable core dumps for all the test children
    230217resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
     
    245232        column = which('column')
    246233        if column:
    247                 cmd = "%s 2> /dev/null" % column
    248                 proc = Popen(cmd, stdin=PIPE, stderr=None, shell=True)
    249                 proc.communicate(input=bytes(text + "\n", "UTF-8"))
     234                subprocess.run(column, input=bytes(text + "\n", "UTF-8"))
    250235        else:
    251236                print(text)
Note: See TracChangeset for help on using the changeset viewer.