Skip to content

Commit

Permalink
__slots__ for concurrency blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Feb 16, 2018
1 parent 370c7ab commit a191d24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion chainlet/concurrency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class LocalExecutor(object):
:param identifier: base identifier for all workers
:type identifier: str
"""
_min_workers = max(CPU_CONCURRENCY, 2)
__slots__ = ('identifier', '_max_workers')

def __init__(self, max_workers, identifier=''):
self.identifier = identifier or ('%s_%d' % (self.__class__.__name__, id(self)))
Expand Down Expand Up @@ -244,6 +244,7 @@ class ConcurrentBundle(bundle.Bundle):
Concurrent bundles implement element concurrency:
the same data is processed concurrently by multiple elements.
"""
__slots__ = ()
executor = DEFAULT_EXECUTOR

def chainlet_send(self, value=None):
Expand Down Expand Up @@ -275,6 +276,7 @@ class ConcurrentChain(chain.Chain):
:note: A :py:class:`ConcurrentChain` will *always* :term:`join`
and :term:`fork` to handle all data.
"""
__slots__ = ('_stripes',)
executor = DEFAULT_EXECUTOR

def __init__(self, elements):
Expand Down
5 changes: 4 additions & 1 deletion chainlet/concurrency/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ class ThreadPoolExecutor(LocalExecutor):
:param identifier: base identifier for all workers
:type identifier: str
"""
_min_workers = max(CPU_CONCURRENCY, 2)
__slots__ = ('_workers', '_queue', '_min_workers')

def __init__(self, max_workers, identifier=''):
super(ThreadPoolExecutor, self).__init__(max_workers=max_workers, identifier=identifier)
self._min_workers = max(CPU_CONCURRENCY, 2)
self._workers = set()
self._queue = queue.Queue()
self._ensure_worker()
Expand Down Expand Up @@ -115,6 +116,7 @@ class ThreadLinkPrimitives(linker.LinkPrimitives):
class ThreadBundle(ConcurrentBundle):
chain_types = ThreadLinkPrimitives()
executor = DEFAULT_EXECUTOR
__slots__ = ()

def __repr__(self):
return 'threads(%s)' % super(ThreadBundle, self).__repr__()
Expand All @@ -123,6 +125,7 @@ def __repr__(self):
class ThreadChain(ConcurrentChain):
chain_types = ThreadLinkPrimitives()
executor = DEFAULT_EXECUTOR
__slots__ = ()

def __repr__(self):
return 'threads(%s)' % super(ThreadChain, self).__repr__()
Expand Down

0 comments on commit a191d24

Please sign in to comment.