本文整理汇总了Python中multiprocessing.managers.SyncManager方法的典型用法代码示例。如果您正苦于以下问题:Python managers.SyncManager方法的具体用法?Python managers.SyncManager怎么用?Python managers.SyncManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.managers
的用法示例。
在下文中一共展示了managers.SyncManager方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def Manager():
'''
Returns a manager associated with a running server process
The managers methods such as `Lock()`, `Condition()` and `Queue()`
can be used to create shared objects.
'''
from multiprocessing.managers import SyncManager
m = SyncManager()
m.start()
return m
#brython fix me
#def Pipe(duplex=True):
# '''
# Returns two connection object connected by a pipe
# '''
# from multiprocessing.connection import Pipe
# return Pipe(duplex)
示例2: Manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def Manager():
'''
Returns a manager associated with a running server process
The managers methods such as `Lock()`, `Condition()` and `Queue()`
can be used to create shared objects.
'''
from multiprocessing.managers import SyncManager
m = SyncManager()
m.start()
return m
示例3: _manticore_multiprocessing
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _manticore_multiprocessing(self):
def raise_signal():
signal.signal(signal.SIGINT, signal.SIG_IGN)
self._worker_type = WorkerProcess
# This is the global manager that will handle all shared memory access
# See. https://docs.python.org/3/library/multiprocessing.html#multiprocessing.managers.SyncManager
self._manager = SyncManager()
self._manager.start(raise_signal)
# The main manticore lock. Acquire this for accessing shared objects
# THINKME: we use the same lock to access states lists and shared contexts
self._lock = self._manager.Condition()
self._killed = self._manager.Value(bool, False)
self._running = self._manager.Value(bool, False)
# List of state ids of States on storage
self._ready_states = self._manager.list()
self._terminated_states = self._manager.list()
self._busy_states = self._manager.list()
self._killed_states = self._manager.list()
self._shared_context = self._manager.dict()
self._context_value_types = {list: self._manager.list, dict: self._manager.dict}
# Decorators added first for convenience.
示例4: make_worker_manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def make_worker_manager(ip, port, authkey):
""" Create a manager for a client. This manager connects to a server on the
given address and exposes the get_job_q and get_result_q methods for
accessing the shared queues from the server.
Return a manager object.
"""
class ServerQueueManager(SyncManager):
pass
ServerQueueManager.register('get_job_q')
ServerQueueManager.register('get_result_q')
manager = ServerQueueManager(address=(ip, port), authkey=authkey)
manager.connect()
logging.info("Worker connected to {:s}:{:d}".format(ip, port))
return manager
示例5: _multiprocessing_transform
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _multiprocessing_transform():
module = astroid.parse('''
from multiprocessing.managers import SyncManager
def Manager():
return SyncManager()
''')
if not PY34:
return module
# On Python 3.4, multiprocessing uses a getattr lookup inside contexts,
# in order to get the attributes they need. Since it's extremely
# dynamic, we use this approach to fake it.
node = astroid.parse('''
from multiprocessing.context import DefaultContext, BaseContext
default = DefaultContext()
base = BaseContext()
''')
try:
context = next(node['default'].infer())
base = next(node['base'].infer())
except exceptions.InferenceError:
return module
for node in (context, base):
for key, value in node.locals.items():
if key.startswith("_"):
continue
value = value[0]
if isinstance(value, astroid.FunctionDef):
# We need to rebound this, since otherwise
# it will have an extra argument (self).
value = astroid.BoundMethod(value, node)
module[key] = value
return module
示例6: _multiprocessing_transform
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _multiprocessing_transform():
module = astroid.parse(
"""
from multiprocessing.managers import SyncManager
def Manager():
return SyncManager()
"""
)
if not PY34:
return module
# On Python 3.4, multiprocessing uses a getattr lookup inside contexts,
# in order to get the attributes they need. Since it's extremely
# dynamic, we use this approach to fake it.
node = astroid.parse(
"""
from multiprocessing.context import DefaultContext, BaseContext
default = DefaultContext()
base = BaseContext()
"""
)
try:
context = next(node["default"].infer())
base = next(node["base"].infer())
except exceptions.InferenceError:
return module
for node in (context, base):
for key, value in node.locals.items():
if key.startswith("_"):
continue
value = value[0]
if isinstance(value, astroid.FunctionDef):
# We need to rebound this, since otherwise
# it will have an extra argument (self).
value = astroid.BoundMethod(value, node)
module[key] = value
return module
示例7: __init__
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def __init__(self, parallelism: int = PARALLELISM):
super().__init__(parallelism=parallelism)
self.manager: Optional[SyncManager] = None
self.result_queue: Optional['Queue[TaskInstanceStateType]'] = None
self.workers: List[QueuedLocalWorker] = []
self.workers_used: int = 0
self.workers_active: int = 0
self.impl: Optional[Union['LocalExecutor.UnlimitedParallelism',
'LocalExecutor.LimitedParallelism']] = None
示例8: _ignore_sigint_manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _ignore_sigint_manager():
"""Context-managed SyncManager which ignores SIGINT interrupt signals."""
manager = SyncManager()
try:
manager.start(_ignore_sigint_initializer)
yield manager
finally:
manager.shutdown()
示例9: _receive
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _receive(self):
while True:
# If we don't have any listeners, we don't want to be checking
# the queue. In particular, since this is a daemon thread, it
# will keep running up until the process exits, and at that time
# the queue object can become unreliable because it's managed by
# a SyncManager that depends on a separate process. This listener
# check makes sure we're only using the queue during an actual
# Flow.get call.
# See here for what happens if we don't have this check:
# https://github.com/square/bionic/issues/161
self._event_has_listeners.wait()
if self._queue.empty():
self._event_queue_is_empty.set()
else:
self._event_queue_is_empty.clear()
try:
record = self._queue.get(timeout=0.05)
except queue.Empty: # Nothing to receive from the queue.
continue
logger = logging.getLogger(record.name)
try:
if logger.isEnabledFor(record.levelno):
logger.handle(record)
except (BrokenPipeError, EOFError):
break
except Exception as e:
logger = logging.getLogger()
try:
logger.warn("exception while logging ", e)
except (BrokenPipeError, EOFError):
break
except Exception:
traceback.print_exc(file=sys.stderr)
示例10: make_server_manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def make_server_manager(port, authkey):
job_q = queue.Queue()
result_q = queue.Queue()
class JobQueueManager(SyncManager):
pass
JobQueueManager.register('get_job_q', callable=lambda: job_q)
JobQueueManager.register('get_result_q', callable=lambda: result_q)
manager = JobQueueManager(address=('', port), authkey=authkey)
manager.start()
print('Server started at port %s' % port)
return manager
示例11: make_client_manager
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def make_client_manager(ip, port, authkey):
class ServerQueueManager(SyncManager):
pass
ServerQueueManager.register('get_job_q')
ServerQueueManager.register('get_result_q')
manager = ServerQueueManager(address=(ip, port), authkey=authkey)
manager.connect()
print('Client connected to %s:%s' % (ip, port))
return manager
示例12: _multiprocessing_managers_transform
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _multiprocessing_managers_transform():
return astroid.parse('''
import array
import threading
import multiprocessing.pool as pool
import six
class Namespace(object):
pass
class Value(object):
def __init__(self, typecode, value, lock=True):
self._typecode = typecode
self._value = value
def get(self):
return self._value
def set(self, value):
self._value = value
def __repr__(self):
return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value)
value = property(get, set)
def Array(typecode, sequence, lock=True):
return array.array(typecode, sequence)
class SyncManager(object):
Queue = JoinableQueue = six.moves.queue.Queue
Event = threading.Event
RLock = threading.RLock
BoundedSemaphore = threading.BoundedSemaphore
Condition = threading.Condition
Barrier = threading.Barrier
Pool = pool.Pool
list = list
dict = dict
Value = Value
Array = Array
Namespace = Namespace
__enter__ = lambda self: self
__exit__ = lambda *args: args
def start(self, initializer=None, initargs=None):
pass
def shutdown(self):
pass
''')
示例13: _multiprocessing_managers_transform
# 需要导入模块: from multiprocessing import managers [as 别名]
# 或者: from multiprocessing.managers import SyncManager [as 别名]
def _multiprocessing_managers_transform():
return astroid.parse(
"""
import array
import threading
import multiprocessing.pool as pool
import six
class Namespace(object):
pass
class Value(object):
def __init__(self, typecode, value, lock=True):
self._typecode = typecode
self._value = value
def get(self):
return self._value
def set(self, value):
self._value = value
def __repr__(self):
return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value)
value = property(get, set)
def Array(typecode, sequence, lock=True):
return array.array(typecode, sequence)
class SyncManager(object):
Queue = JoinableQueue = six.moves.queue.Queue
Event = threading.Event
RLock = threading.RLock
BoundedSemaphore = threading.BoundedSemaphore
Condition = threading.Condition
Barrier = threading.Barrier
Pool = pool.Pool
list = list
dict = dict
Value = Value
Array = Array
Namespace = Namespace
__enter__ = lambda self: self
__exit__ = lambda *args: args
def start(self, initializer=None, initargs=None):
pass
def shutdown(self):
pass
"""
)