Skip to content

Commit

Permalink
Atexit support improved
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Jul 19, 2018
1 parent 302c914 commit 118ea1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
@@ -1,6 +1,7 @@
1.6.7
-----
* Started testing Python 3.7 as well.
* Avoid throwing error in atexit in special cases (like pytest)

1.6.6
-----
Expand Down
2 changes: 2 additions & 0 deletions plumbum/colorlib/styles.py
Expand Up @@ -370,6 +370,8 @@ def stdout(self):
It will use current sys.stdout if set to None (default).
Unfortunately, it only works on an instance..
"""
# Import sys repeated here to make calling this stable in atexit function
import sys
return self.__class__._stdout if self.__class__._stdout is not None else sys.stdout

@stdout.setter
Expand Down
8 changes: 5 additions & 3 deletions plumbum/commands/processes.py
Expand Up @@ -187,9 +187,11 @@ def _register_proc_timeout(proc, timeout):
def _shutdown_bg_threads():
global _shutting_down
_shutting_down = True
_timeout_queue.put((SystemExit, 0))
# grace period
bgthd.join(0.1)
# Make sure this still exists (don't throw error in atexit!)
if _timeout_queue:
_timeout_queue.put((SystemExit, 0))
# grace period
bgthd.join(0.1)


atexit.register(_shutdown_bg_threads)
Expand Down

0 comments on commit 118ea1b

Please sign in to comment.