-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from kingosticks/fix-startup-time
Fix startup time (Fixes #343)
- Loading branch information
Showing
6 changed files
with
243 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import threading | ||
|
||
|
||
class ThreadJoiner: | ||
def __init__(self, timeout: int = 1): | ||
self.timeout = timeout | ||
|
||
def __enter__(self): | ||
self.before = set(threading.enumerate()) | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
new_threads = set(threading.enumerate()) - self.before | ||
for thread in new_threads: | ||
thread.join(timeout=self.timeout) | ||
if thread.is_alive(): | ||
raise RuntimeError(f"Timeout joining thread {thread}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.