Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates -- either normally or through an unhandled exception or until the optional timeout occurs. When the timeout argument is present and not None, i
(self, timeout=None)
| 1095 | # current_thread()), and would block. |
| 1096 | |
| 1097 | def join(self, timeout=None): |
| 1098 | """Wait until the thread terminates. |
| 1099 | |
| 1100 | This blocks the calling thread until the thread whose join() method is |
| 1101 | called terminates -- either normally or through an unhandled exception |
| 1102 | or until the optional timeout occurs. |
| 1103 | |
| 1104 | When the timeout argument is present and not None, it should be a |
| 1105 | floating-point number specifying a timeout for the operation in seconds |
| 1106 | (or fractions thereof). As join() always returns None, you must call |
| 1107 | is_alive() after join() to decide whether a timeout happened -- if the |
| 1108 | thread is still alive, the join() call timed out. |
| 1109 | |
| 1110 | When the timeout argument is not present or None, the operation will |
| 1111 | block until the thread terminates. |
| 1112 | |
| 1113 | A thread can be join()ed many times. |
| 1114 | |
| 1115 | join() raises a RuntimeError if an attempt is made to join the current |
| 1116 | thread as that would cause a deadlock. It is also an error to join() a |
| 1117 | thread before it has been started and attempts to do so raises the same |
| 1118 | exception. |
| 1119 | |
| 1120 | """ |
| 1121 | if not self._initialized: |
| 1122 | raise RuntimeError("Thread.__init__() not called") |
| 1123 | if not self._started.is_set(): |
| 1124 | raise RuntimeError("cannot join thread before it is started") |
| 1125 | if self is current_thread(): |
| 1126 | raise RuntimeError("cannot join current thread") |
| 1127 | |
| 1128 | # the behavior of a negative timeout isn't documented, but |
| 1129 | # historically .join(timeout=x) for x<0 has acted as if timeout=0 |
| 1130 | if timeout is not None: |
| 1131 | timeout = max(timeout, 0) |
| 1132 | |
| 1133 | self._os_thread_handle.join(timeout) |
| 1134 | |
| 1135 | @property |
| 1136 | def name(self): |