Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_OUT_EXPECTED = ['ONE', 'TWO', 'THREE']
# Code for the subprocess.
if 'PYI_THREAD_TEST_CASE' in os.environ:
class TestThreadClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print 'ONE'
print 'TWO'
print 'THREE'
# Main process should not exit before the thread stops.
# This is the behaviour of Python interpreter.
TestThreadClass().start()
# Execute itself in a subprocess.
else:
# Differenciate subprocess code.
itself = sys.argv[0]
# Run subprocess.
try:
import subprocess
proc = subprocess.Popen([itself], stdout=subprocess.PIPE,
env={'PYI_THREAD_TEST_CASE': 'any_string'},
stderr=subprocess.PIPE, shell=False)
# Waits for subprocess to complete.
out, err = proc.communicate()
except ImportError:
# Python 2.3 does not have subprocess module.