<s> """<STR_LIT>""" <EOL> import logging <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import threading <EOL> _popen_lock = threading . Lock ( ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> _SUBPROCESS_STDIN_IS_THREAD_HOSTILE = True <EOL> else : <EOL> _SUBPROCESS_STDIN_IS_THREAD_HOSTILE = False <EOL> def start_process ( args , input_string = '<STR_LIT>' , env = None , cwd = None , stdout = None , <EOL> stderr = None ) : <EOL> """<STR_LIT>""" <EOL> with _popen_lock : <EOL> logging . debug ( '<STR_LIT>' , <EOL> args , input_string , env , cwd ) <EOL> if ( hasattr ( subprocess , '<STR_LIT>' ) and <EOL> hasattr ( subprocess , '<STR_LIT>' ) ) : <EOL> startupinfo = subprocess . STARTUPINFO ( ) <EOL> startupinfo . dwFlags = subprocess . STARTF_USESHOWWINDOW <EOL> startupinfo . wShowWindow = subprocess . SW_HIDE <EOL> else : <EOL> startupinfo = None <EOL> p = subprocess . Popen ( args , env = env , cwd = cwd , stdout = stdout , stderr = stderr , <EOL> stdin = subprocess . PIPE , startupinfo = startupinfo ) <EOL> if _SUBPROCESS_STDIN_IS_THREAD_HOSTILE : <EOL> p . stdin . write ( input_string ) <EOL> p . stdin . close ( ) <EOL> p . stdin = None <EOL> if not _SUBPROCESS_STDIN_IS_THREAD_HOSTILE : <EOL> p . stdin . write ( input_string ) <EOL> p . stdin . close ( ) <EOL> p . stdin = None <EOL> return p <EOL> def start_process_file ( args , input_string , env , cwd , stdin = None , stdout = None , <EOL> stderr = None ) : <EOL> """<STR_LIT>""" <EOL> child_in = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:wb>' , delete = False ) <EOL> child_out = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:rb>' , delete = False ) <EOL> child_in . write ( input_string ) <EOL> child_in . close ( ) <EOL> args = args + [ child_in . name , child_out . name ] <EOL> with _popen_lock : <EOL> logging . debug ( '<STR_LIT>' , <EOL> args , input_string , env , cwd ) <EOL> p = subprocess . Popen ( args , env = env , cwd = cwd , stdin = stdin , stdout = stdout , <EOL> stderr = stderr ) <EOL> p . child_out = child_out <EOL> return p </s>
