本文整理匯總了Python中multiprocessing.connection.wait方法的典型用法代碼示例。如果您正苦於以下問題:Python connection.wait方法的具體用法?Python connection.wait怎麽用?Python connection.wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing.connection
的用法示例。
在下文中一共展示了connection.wait方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rollout
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def rollout(self, policy, train, epoch, discard_other_rollout_type=False):
if not self.workers_alive():
raise RuntimeError("Worker has died prematurely.")
# prevent starvation if only one worker
if discard_other_rollout_type:
self._discard_rollout_promises(not train)
self._alloc_rollout_promise(policy, train, epoch)
# Check if remote path has been collected.
ready_promises = wait(self.rollout_promise_list[train], timeout=0)
for rollout_promise in ready_promises:
rollout = rollout_promise.recv()
path_epoch, _ = self.pipe_info[rollout_promise]
self._free_rollout_promise(rollout_promise)
# Throw away eval paths from previous epochs
if path_epoch != epoch and train == False:
continue
self._alloc_rollout_promise(policy, train, epoch)
return rollout
return None
示例2: shutdown
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown_thread = True
if self._queue_management_thread:
# Wake up queue management thread
self._queue_management_thread_wakeup.wakeup()
if wait:
self._queue_management_thread.join()
# To reduce the risk of opening too many files, remove references to
# objects that use file descriptors.
self._queue_management_thread = None
if self._call_queue is not None:
self._call_queue.close()
if wait:
self._call_queue.join_thread()
self._call_queue = None
self._result_queue = None
self._processes = None
if self._queue_management_thread_wakeup:
self._queue_management_thread_wakeup.close()
self._queue_management_thread_wakeup = None
示例3: _free_rollout_promise
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def _free_rollout_promise(self, pipe):
_, train = self.pipe_info[pipe]
assert pipe not in self.free_pipes
if wait([pipe], timeout=0):
pipe.recv()
self.free_pipes.add(pipe)
del self.pipe_info[pipe]
self.rollout_promise_list[train].remove(pipe)
示例4: _discard_rollout_promises
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def _discard_rollout_promises(self, train_type):
ready_promises = wait(self.rollout_promise_list[train_type], timeout=0)
for rollout_promise in ready_promises:
self._free_rollout_promise(rollout_promise)
示例5: _worker_loop
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def _worker_loop(pipe, *worker_env_args, **worker_env_kwargs):
env = RemoteRolloutEnv.WorkerEnv(*worker_env_args, **worker_env_kwargs)
while True:
wait([pipe])
env_update, rollout_args = pipe.recv()
if env_update is not None:
env._env.update_env(**env_update)
rollout = env.rollout(*rollout_args)
pipe.send(rollout)
示例6: __init__
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def __init__(self, _ActorClass, *args, **kwargs):
process._check_system_limits()
self._ActorClass = _ActorClass
# todo: If we want to cancel futures we need to give the task_queue a
# maximum size
self._call_queue = multiprocessing.JoinableQueue()
self._call_queue._ignore_epipe = True
self._result_queue = multiprocessing.Queue()
self._work_ids = queue.Queue()
self._queue_management_thread = None
# We only maintain one process for our actor
self._manager = None
# Shutdown is a two-step process.
self._shutdown_thread = False
self._shutdown_lock = threading.Lock()
self._broken = False
self._queue_count = 0
self._pending_work_items = {}
self._did_initialize = False
if args or kwargs:
# If given actor initialization args we must start the Actor
# immediately. Otherwise just wait until we get a message
print('Init with args')
print('args = %r' % (args,))
self._initialize_actor(*args, **kwargs)
示例7: shutdown
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown_thread = True
if self._queue_management_thread:
# Wake up queue management thread
self._result_queue.put(None)
if wait:
self._queue_management_thread.join()
# To reduce the risk of opening too many files, remove references to
# objects that use file descriptors.
self._queue_management_thread = None
self._call_queue = None
self._result_queue = None
self._manager = None
示例8: map
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def map(self, fn, *iterables, timeout=None, chunksize=1):
"""Returns an iterator equivalent to map(fn, iter).
Args:
fn: A callable that will take as many arguments as there are
passed iterables.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
chunksize: If greater than one, the iterables will be chopped into
chunks of size chunksize and submitted to the process pool.
If set to one, the items in the list will be sent one at a time.
Returns:
An iterator equivalent to: map(func, *iterables) but the calls may
be evaluated out-of-order.
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
Exception: If fn(*args) raises for any values.
"""
if chunksize < 1:
raise ValueError("chunksize must be >= 1.")
results = super().map(partial(_process_chunk, fn),
_get_chunks(*iterables, chunksize=chunksize),
timeout=timeout)
return itertools.chain.from_iterable(results)
示例9: shutdown
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown_thread = True
if self._queue_management_thread:
# Wake up queue management thread
self._result_queue.put(None)
if wait:
self._queue_management_thread.join()
# To reduce the risk of opening too many files, remove references to
# objects that use file descriptors.
self._queue_management_thread = None
self._call_queue = None
self._result_queue = None
self._processes = None
示例10: wait
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def wait(self, timeout=None):
if self.returncode is None:
if timeout is not None:
from multiprocessing.connection import wait
if not wait([self.sentinel], timeout):
return None
# This shouldn't block if wait() returned successfully.
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
return self.returncode
示例11: terminate
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def terminate(self):
if self.returncode is None:
try:
os.kill(self.pid, signal.SIGTERM)
except ProcessLookupError:
pass
except OSError:
if self.wait(timeout=0.1) is None:
raise
示例12: poll
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def poll(self, flag=os.WNOHANG):
if self.returncode is None:
from multiprocessing.connection import wait
timeout = 0 if flag == os.WNOHANG else None
if not wait([self.sentinel], timeout):
return None
try:
self.returncode = forkserver.read_unsigned(self.sentinel)
except (OSError, EOFError):
# The process ended abnormally perhaps because of a signal
self.returncode = 255
return self.returncode
示例13: map
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def map(self, fn, *iterables, timeout=None, chunksize=1):
"""Returns an iterator equivalent to map(fn, iter).
Args:
fn: A callable that will take as many arguments as there are
passed iterables.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
chunksize: If greater than one, the iterables will be chopped into
chunks of size chunksize and submitted to the process pool.
If set to one, the items in the list will be sent one at a time.
Returns:
An iterator equivalent to: map(func, *iterables) but the calls may
be evaluated out-of-order.
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
Exception: If fn(*args) raises for any values.
"""
if chunksize < 1:
raise ValueError("chunksize must be >= 1.")
results = super().map(partial(_process_chunk, fn),
_get_chunks(*iterables, chunksize=chunksize),
timeout=timeout)
return _chain_from_iterable_of_lists(results)
示例14: _send_signal
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def _send_signal(self, sig):
if self.returncode is None:
try:
os.kill(self.pid, sig)
except ProcessLookupError:
pass
except OSError:
if self.wait(timeout=0.1) is None:
raise
示例15: poll
# 需要導入模塊: from multiprocessing import connection [as 別名]
# 或者: from multiprocessing.connection import wait [as 別名]
def poll(self, flag=os.WNOHANG):
if self.returncode is None:
from multiprocessing.connection import wait
timeout = 0 if flag == os.WNOHANG else None
if not wait([self.sentinel], timeout):
return None
try:
self.returncode = forkserver.read_signed(self.sentinel)
except (OSError, EOFError):
# This should not happen usually, but perhaps the forkserver
# process itself got killed
self.returncode = 255
return self.returncode