Python thread.start_new() Examples
The following are 12
code examples of thread.start_new().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
thread
, or try the search function
.
Example #1
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 6 votes |
def intercept_threads(for_attach = False): thread.start_new_thread = thread_creator thread.start_new = thread_creator # If threading has already been imported (i.e. we're attaching), we must hot-patch threading._start_new_thread # so that new threads started using it will be intercepted by our code. # # On the other hand, if threading has not been imported, we must not import it ourselves, because it will then # treat the current thread as the main thread, which is incorrect when attaching because this code is executing # on an ephemeral debugger attach thread that will go away shortly. We don't need to hot-patch it in that case # anyway, because it will pick up the new thread.start_new_thread that we have set above when it's imported. global _threading if _threading is None and 'threading' in sys.modules: import threading _threading = threading _threading._start_new_thread = thread_creator global _INTERCEPTING_FOR_ATTACH _INTERCEPTING_FOR_ATTACH = for_attach
Example #2
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 6 votes |
def intercept_threads(for_attach = False): thread.start_new_thread = thread_creator thread.start_new = thread_creator # If threading has already been imported (i.e. we're attaching), we must hot-patch threading._start_new_thread # so that new threads started using it will be intercepted by our code. # # On the other hand, if threading has not been imported, we must not import it ourselves, because it will then # treat the current thread as the main thread, which is incorrect when attaching because this code is executing # on an ephemeral debugger attach thread that will go away shortly. We don't need to hot-patch it in that case # anyway, because it will pick up the new thread.start_new_thread that we have set above when it's imported. global _threading if _threading is None and 'threading' in sys.modules: import threading _threading = threading _threading._start_new_thread = thread_creator global _INTERCEPTING_FOR_ATTACH _INTERCEPTING_FOR_ATTACH = for_attach
Example #3
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 6 votes |
def intercept_threads(for_attach = False): thread.start_new_thread = thread_creator thread.start_new = thread_creator # If threading has already been imported (i.e. we're attaching), we must hot-patch threading._start_new_thread # so that new threads started using it will be intercepted by our code. # # On the other hand, if threading has not been imported, we must not import it ourselves, because it will then # treat the current thread as the main thread, which is incorrect when attaching because this code is executing # on an ephemeral debugger attach thread that will go away shortly. We don't need to hot-patch it in that case # anyway, because it will pick up the new thread.start_new_thread that we have set above when it's imported. global _threading if _threading is None and 'threading' in sys.modules: import threading _threading = threading _threading._start_new_thread = thread_creator global _INTERCEPTING_FOR_ATTACH _INTERCEPTING_FOR_ATTACH = for_attach
Example #4
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 6 votes |
def intercept_threads(for_attach = False): thread.start_new_thread = thread_creator thread.start_new = thread_creator # If threading has already been imported (i.e. we're attaching), we must hot-patch threading._start_new_thread # so that new threads started using it will be intercepted by our code. # # On the other hand, if threading has not been imported, we must not import it ourselves, because it will then # treat the current thread as the main thread, which is incorrect when attaching because this code is executing # on an ephemeral debugger attach thread that will go away shortly. We don't need to hot-patch it in that case # anyway, because it will pick up the new thread.start_new_thread that we have set above when it's imported. global _threading if _threading is None and 'threading' in sys.modules: import threading _threading = threading _threading._start_new_thread = thread_creator global _INTERCEPTING_FOR_ATTACH _INTERCEPTING_FOR_ATTACH = for_attach
Example #5
Source File: TraceCollector.py From ironpython2 with Apache License 2.0 | 5 votes |
def __init__(self, *args): winout.WindowOutput.__init__(*(self,)+args) self.hStopThread = win32event.CreateEvent(None, 0, 0, None) thread.start_new(CollectorThread, (self.hStopThread, self))
Example #6
Source File: mdi_pychecker.py From ironpython2 with Apache License 2.0 | 5 votes |
def startPycheckerRun(self): self.result=None old=win32api.SetCursor(win32api.LoadCursor(0, win32con.IDC_APPSTARTING)) win32ui.GetApp().AddIdleHandler(self.idleHandler) import thread thread.start_new(self.threadPycheckerRun,()) ##win32api.SetCursor(old)
Example #7
Source File: testGIT.py From ironpython2 with Apache License 2.0 | 5 votes |
def BeginThreadsSimpleMarshal(numThreads, cookie): """Creates multiple threads using simple (but slower) marshalling. Single interpreter object, but a new stream is created per thread. Returns the handles the threads will set when complete. """ ret = [] for i in range(numThreads): hEvent = win32event.CreateEvent(None, 0, 0, None) thread.start_new(TestInterpInThread, (hEvent, cookie)) ret.append(hEvent) return ret
Example #8
Source File: test_thread.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_start_new(self): #--Sanity global CALLED CALLED = False def tempFunc(): global CALLED CALLED = 3.14 thread.start_new(tempFunc, ()) while CALLED==False: print ".", time.sleep(0.1) self.assertEqual(CALLED, 3.14) CALLED = False
Example #9
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def detach_process(): global DETACHED DETACHED = True if not _INTERCEPTING_FOR_ATTACH: if isinstance(sys.stdout, _DebuggerOutput): sys.stdout = sys.stdout.old_out if isinstance(sys.stderr, _DebuggerOutput): sys.stderr = sys.stderr.old_out if not _INTERCEPTING_FOR_ATTACH: thread.start_new_thread = _start_new_thread thread.start_new = _start_new_thread
Example #10
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def detach_process(): global DETACHED DETACHED = True if not _INTERCEPTING_FOR_ATTACH: if isinstance(sys.stdout, _DebuggerOutput): sys.stdout = sys.stdout.old_out if isinstance(sys.stderr, _DebuggerOutput): sys.stderr = sys.stderr.old_out if not _INTERCEPTING_FOR_ATTACH: thread.start_new_thread = _start_new_thread thread.start_new = _start_new_thread
Example #11
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def detach_process(): global DETACHED DETACHED = True if not _INTERCEPTING_FOR_ATTACH: if isinstance(sys.stdout, _DebuggerOutput): sys.stdout = sys.stdout.old_out if isinstance(sys.stderr, _DebuggerOutput): sys.stderr = sys.stderr.old_out if not _INTERCEPTING_FOR_ATTACH: thread.start_new_thread = _start_new_thread thread.start_new = _start_new_thread
Example #12
Source File: fork_wait.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_wait(self): for i in range(NUM_THREADS): thread.start_new(self.f, (i,)) time.sleep(LONGSLEEP) a = self.alive.keys() a.sort() self.assertEquals(a, range(NUM_THREADS)) prefork_lives = self.alive.copy() if sys.platform in ['unixware7']: cpid = os.fork1() else: cpid = os.fork() if cpid == 0: # Child time.sleep(LONGSLEEP) n = 0 for key in self.alive: if self.alive[key] != prefork_lives[key]: n += 1 os._exit(n) else: # Parent self.wait_impl(cpid) # Tell threads to die self.stop = 1 time.sleep(2*SHORTSLEEP) # Wait for threads to die