本文整理匯總了Python中multiprocessing.queues.SimpleQueue方法的典型用法代碼示例。如果您正苦於以下問題:Python queues.SimpleQueue方法的具體用法?Python queues.SimpleQueue怎麽用?Python queues.SimpleQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing.queues
的用法示例。
在下文中一共展示了queues.SimpleQueue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SimpleQueue
# 需要導入模塊: from multiprocessing import queues [as 別名]
# 或者: from multiprocessing.queues import SimpleQueue [as 別名]
def SimpleQueue():
'''
Returns a queue object
'''
from multiprocessing.queues import SimpleQueue
return SimpleQueue()
示例2: put
# 需要導入模塊: from multiprocessing import queues [as 別名]
# 或者: from multiprocessing.queues import SimpleQueue [as 別名]
def put(self, obj):
bytes = pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL)
# follow SimpleQueue, need to deal with _wlock being None
if self._wlock is None:
self._writer.send_bytes(bytes)
else:
with self._wlock:
self._writer.send_bytes(bytes)
示例3: SimpleQueue
# 需要導入模塊: from multiprocessing import queues [as 別名]
# 或者: from multiprocessing.queues import SimpleQueue [as 別名]
def SimpleQueue(self):
return FastQ(ctx=self.get_context())
示例4: run_sp
# 需要導入模塊: from multiprocessing import queues [as 別名]
# 或者: from multiprocessing.queues import SimpleQueue [as 別名]
def run_sp(func, *args, **kwargs):
"""
Run a function in a subprocess and return its value. This is for achieving subprocess
isolation, not parallelism. The subprocess is configured so things like logging work
correctly, and is initialized with a derived random seed.
"""
ctx = LKContext.INSTANCE
rq = ctx.SimpleQueue()
seed = derive_seed(none_on_old_numpy=True)
worker_args = (log_queue(), seed, rq, func, args, kwargs)
_log.debug('spawning subprocess to run %s', func)
proc = ctx.Process(target=_sp_worker, args=worker_args)
proc.start()
_log.debug('waiting for process %s to return', proc)
success, payload = rq.get()
_log.debug('received success=%s', success)
_log.debug('waiting for process %s to exit', proc)
proc.join()
if proc.exitcode:
_log.error('subprocess failed with code %d', proc.exitcode)
raise RuntimeError('subprocess failed with code ' + str(proc.exitcode))
if success:
return payload
else:
_log.error('subprocess raised exception: %s', payload)
raise ChildProcessError('error in child process', payload)