Skip to content

Commit

Permalink
Set threaded=True when multiple processes detected
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Dec 25, 2020
1 parent 4c9833d commit f107cae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions enlighten/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import atexit
from collections import OrderedDict
import multiprocessing
import signal
import sys
import threading
Expand All @@ -39,7 +40,7 @@ class Manager(object):
enabled(bool): Status (Default: True)
no_resize(bool): Disable resizing support
threaded(bool): When True resize handling is deferred until next write (Default: False
unless multiple threads are detected)
unless multiple threads or multiple processes are detected)
kwargs(Dict[str, Any]): Any additional :py:term:`keyword arguments<keyword argument>`
will be used as default values when :py:meth:`counter` is called.
Expand Down Expand Up @@ -74,7 +75,12 @@ def __init__(self, stream=None, counter_class=Counter, **kwargs):
self.enabled = kwargs.get('enabled', True) # Double duty for counters
self.no_resize = kwargs.pop('no_resize', False)
self.set_scroll = kwargs.pop('set_scroll', True)
self.threaded = kwargs.pop('threaded', threading.active_count() > 1)
self.threaded = kwargs.pop(
'threaded',
(threading.active_count() > 1 # Multiple threads
or bool(multiprocessing.active_children()) # Main process with children
or multiprocessing.current_process().name != 'MainProcess') # Child process
)
self.term = Terminal(stream=self.stream)

# Set up companion stream
Expand Down

0 comments on commit f107cae

Please sign in to comment.