def runTest(): global writerAlive global readerAlive writerAlive = True readerAlive = True a = Thread(ThreadStart(reader)) a.IsBackground = True a.Start() if isinstance(writerWorker, tuple): b = [] index = 0 for wr in writerWorker: th = Thread(ThreadStart(writer(wr, index))) th.IsBackground = True th.Start() b.append(th) index = index + 1 else: b = [Thread(ThreadStart(writer(writerWorker, 0)))] b[0].IsBackground = True b[0].Start() go.Set() a.Join() for th in b: th.Join()
def testRun(): autoResetEvent = AutoResetEvent(False) data = {} if hasattr(clr, "SetCommandDispatcher"): # for IP 2.x def setCommandDispatcher(cmd): clr.SetCommandDispatcher(cmd) else: # for IP 1.x def setCommandDispatcher(cmd): IronPython.Hosting.PythonEngine.ConsoleCommandDispatcher = cmd def threadProc(): try: dispatcher = Form(Size=Size(0,0)) dispatcher.Show() # create a dummy control (for invoking commands from) dispatcher.Hide() # and show & hide to initialise it. data["dispatcher"] = dispatcher autoResetEvent.Set() # indicate that we are ready Application.Run() # start the message loop finally: setCommandDispatcher(None) def dispatchConsoleCommand(consoleCommand): dispatcher = data.get("dispatcher") if consoleCommand: dispatcher.Invoke(consoleCommand) else: Application.Exit() t = Thread(ThreadStart(threadProc)) t.IsBackground = True t.Start() autoResetEvent.WaitOne() # Wait until the alt input execution setCommandDispatcher(dispatchConsoleCommand)
def __start_thread_loop(self): ''' Starts (and returns) the background thread, which will wait-loop forever, running tasks that are submitted via the 'submit' method, until it is flagged by the 'shutdown' method to terminate. ''' def threadloop(): task = None while task != self: try: Monitor.Enter(self) try: task = self.task if task != self: self.task = None if task is None: Monitor.Wait(self) finally: Monitor.Exit(self) if task != self and task is not None: task() except Exception as ex: # slightly odd error handling, cause this thread should NEVER # die as the result of an exception! try: log.handle_error(ex) except: pass task = None thread = Thread(ThreadStart(threadloop)) thread.IsBackground = True thread.Start() return thread
def InitializeErrorWatcher(self): from System.Threading import Thread, ThreadStart import thread self.errorLock = thread.allocate_lock() self.errorString = "" th = Thread(ThreadStart(self.WatchErrorStream)) th.IsBackground = True th.Start()
def execute(self, runnable): runner = Runner(runnable) thread = Thread(ThreadStart(runner)) thread.IsBackground = True thread.Start() if not thread.Join(self._timeout * 1000): thread.Abort() raise self._error return runner.get_result()
dispatcher = Form(Size=Size(0, 0)) dispatcher.Show() dispatcher.Hide() # Signal that the thread running thread_proc is ready for the main # thread to send input to it. are.Set() # Start the message loop. Application.Run() finally: # In case thread_proc's thread dies, restore the default IronPython # console execution behavior. clr.SetCommandDispatcher(None) def DispatchConsoleCommand(consoleCommand): if consoleCommand: # consoleCommand is a delegate for a dynamic method that embodies the # input expression from the user. Run it on the other thread. dispatcher.Invoke(consoleCommand) else: Application.Exit() t = Thread(ThreadStart(thread_proc)) t.IsBackground = True t.Start() # Don't establish the alternative input execution behavior until the other # thread is ready. Note, 'are' starts out unsignalled. are.WaitOne() clr.SetCommandDispatcher(DispatchConsoleCommand)
def start(self): log.debug("starting new thread") t = Thread(ThreadStart(self.target)) t.IsBackground = True t.Start()