def multireader(*streams): """creates multiple threads to read std err/std out at the same time to avoid blocking""" class reader(object): def __init__(self, stream): self.stream = stream def __call__(self): self.text = self.stream.readlines() threads = [] readers = [] for stream in streams: curReader = reader(stream) thread = Threading.Thread(Threading.ThreadStart(curReader)) readers.append(curReader) threads.append(thread) thread.Start() for thread in threads: thread.Join() return [curReader.text for curReader in readers]
# # make command # cfg_command = cfg + " --pass 1 " + "--kernel " + CFG_KERNEL cfg_command += " --api-table " + cfg_api_table cfg_command += " " + cfg_cfg1_def_tables + cfg_includes cfg_command += " --ini-file " + cfg_ini_file cfg_command += " " + cfg_input_str print cfg_command # # stop build # def BuildStop(): buid.Stop() # # Execute cfg path 1 # try: output = subprocess.check_output(cfg_command, stderr=subprocess.STDOUT,) except subprocess.CalledProcessError, e: print "ERROR!! : ", e.output thread = Threading.Thread(Threading.ThreadStart(BuildStop)) thread.IsBackground = True thread.Start() print output
def button_click(self, sender, args): new_ui_thread = Threading.Thread( Threading.ThreadStart(self.make_outputwindow)) new_ui_thread.SetApartmentState(Threading.ApartmentState.STA) new_ui_thread.Start() self.do_long_process()