本文整理汇总了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)