def async_task(self, target, *args, **kwargs):
"""Must be used with 'yield', as
'val = yield pool.async_task(target, args, kwargs)'.
@task is task where this method is called.
@target is function/method that will be executed asynchronously in a
thread.
@args and @kwargs are arguments and keyword arguments passed to @target.
This call effectively returns result of executing
'target(*args, **kwargs)'.
"""
if not self._scheduler:
self._scheduler = Pycos.scheduler()
task = Pycos.cur_task(self._scheduler)
# assert isinstance(task, Task)
# if arguments are passed as per Thread call, get args and kwargs
if not args and kwargs:
args = kwargs.pop('args', ())
kwargs = kwargs.pop('kwargs', kwargs)
task._await_()
self._task_queue.put((task, target, args, kwargs))
评论列表
文章目录