Lines Matching defs:thread

31 # #12316 and #11870), and fork() from a worker thread is known to trigger
104 thread = threading.Thread(name="myname1")
105 self.assertEqual(thread.name, "myname1")
108 thread = threading.Thread(name=123)
109 self.assertEqual(thread.name, "123")
112 thread = threading.Thread(target=func, name="myname2")
113 self.assertEqual(thread.name, "myname2")
116 thread = threading.Thread(name="")
117 self.assertEqual(thread.name, "Thread-2")
120 thread = threading.Thread()
121 self.assertEqual(thread.name, "Thread-3")
124 thread = threading.Thread(target=func)
125 self.assertEqual(thread.name, "Thread-5 (func)")
175 t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
199 # The ident still must work for the main thread and dummy threads.
213 # run with a small(ish) thread stack size (256 KiB)
216 print('with 256 KiB thread stack size...')
221 'platform does not support changing thread stack size')
225 # run with a large thread stack size (1 MiB)
228 print('with 1 MiB thread stack size...')
233 'platform does not support changing thread stack size')
238 # Check that a "foreign" thread can use the threading module.
241 # thread to get made in the threading._active map.
249 # Wait for the thread to finish.
271 # First check it works when setting the exception from the same thread.
289 self.assertEqual(result, 1) # one thread state modified
294 # `worker_started` is set by the thread when it's inside a try/except
296 # `worker_saw_exception` is set by the thread upon catching that
318 print(" started worker thread")
320 # Try a thread id that doesn't make sense.
322 print(" trying nonsensical thread id")
324 self.assertEqual(result, 0) # no thread states modified
326 # Now raise an exception in the worker thread.
328 print(" waiting for worker thread to get started")
337 self.assertEqual(result, 1) # one thread state modified
346 # else the thread is still running, and we have no way to kill it
349 # Issue 7481: Failure to start thread should cleanup the limbo map.
365 # very late on python exit: on deallocation of a running thread for
391 ready.acquire() # Be sure the other thread is waiting.
430 # As a non-daemon thread we SHOULD wake up and nothing
442 # Try hard to trigger #1703448: a thread is still returned in
462 # should be cleaned up when the thread completes.
464 self.thread = threading.Thread(target=self._run,
467 self.thread.start()
477 cyclic_object.thread.join()
485 raising_cyclic_object.thread.join()
566 # Issue #14308: a dummy thread in the active list doesn't mess up
677 # bpo-31516: current_thread() should still point to the main thread
707 # until Python thread states of all non-daemon threads get deleted.
728 # Sleep a bit so that the thread is still running when
750 # The tstate lock is None until the thread is started
756 # The tstate lock can't be acquired when the thread is running
761 # When the thread ends, the state_lock can be successfully
765 # prevents is_alive() from knowing the thread's end-of-life C code
771 # And verify the thread disposed of _tstate_lock.
822 # Issue #14432: Crash when a generator is created in a C thread that is
825 # Python state of the destroyed C thread. The crash occurs when a trace
848 # Create a generator in a C thread which exits after the call
852 # Call the generator in a different Python thread, check that the
853 # generator didn't keep a reference to the destroyed thread state
886 thread = threading.Thread(target=event.wait, daemon=daemon)
889 # but only for non-daemon thread
890 thread.start()
891 tstate_lock = thread._tstate_lock
897 # unblock the thread and join it
899 thread.join()
906 # bpo-19466: thread locals must not be deleted before destructors
923 # bpo-41149: A thread that had a boolean value of False would not
925 # is for a thread to do nothing if its target is None, and to call
936 thread = threading.Thread(target=target)
937 thread.start()
938 thread.join()
942 # bpo-37788: Test that a thread which is not joined explicitly
960 # bpo-1596321: If the threading module is first import from a thread
961 # different than the main thread, threading._shutdown() must handle
986 # don't wait until the thread completes
999 # a thread, which waits for the main program to terminate
1002 print('end of thread')
1010 self.assertEqual(data, "end of main\nend of thread\n")
1013 # The usual case: on exit, wait for a non-daemon thread
1048 # Like the test above, but fork() was called from a worker thread
1076 # Check that a daemon thread cannot crash the interpreter on shutdown
1078 # the main thread.
1189 # Sleep a bit so that the thread is still running when
1199 # The thread was joined properly.
1203 # Same as above, but a delay gets introduced after the thread's
1204 # Python code returned but before the thread state is deleted.
1205 # To achieve this, we register a thread-local object which sleeps
1225 # Sleep a bit so that the thread is still running when
1236 # The thread was joined properly.
1247 # Make sure the daemon thread is still running when
1260 "not the last thread", err.decode())
1267 thread = threading.Thread()
1268 thread.start()
1269 self.assertRaises(RuntimeError, thread.start)
1270 thread.join()
1277 thread = threading.Thread()
1278 self.assertRaises(RuntimeError, thread.join)
1281 thread = threading.Thread()
1282 thread.start()
1283 self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
1284 thread.join()
1293 # test that excessive recursion within a non-main thread causes
1312 print('end of main thread')
1314 expected_output = "end of main thread\n"
1344 self.assertIn("Exception in thread", err)
1373 self.assertIn("Exception in thread", err)
1416 thread = Issue27558()
1417 thread.start()
1418 thread.join()
1419 self.assertIsNotNone(thread.exc)
1420 self.assertIsInstance(thread.exc, RuntimeError)
1421 # explicitly break the reference cycle to not leak a dangling thread
1422 thread.exc = None
1453 thread = ThreadRunFail(name="excepthook thread")
1454 thread.start()
1455 thread.join()
1458 self.assertIn(f'Exception in thread {thread.name}:\n', stderr)
1465 # threading.excepthook called with thread=None: log the thread
1479 self.assertIn(f'Exception in thread {threading.get_ident()}:\n', stderr)
1491 thread = ThreadExit()
1492 thread.start()
1493 thread.join()
1506 thread = ThreadRunFail()
1507 thread.start()
1508 thread.join()
1513 self.assertIs(args.thread, thread)
1531 thread = ThreadRunFail()
1532 thread.start()
1533 thread.join()
1542 thread = ThreadRunFail(name="excepthook thread")
1543 thread.start()
1544 thread.join()
1548 print("Running a thread failed", file=sys.stderr)
1558 self.assertEqual(custom_hook_output, "Running a thread failed\n")
1665 # Make sure that if interrupt_main is called in main thread that