我想知道 Python 中是否有任何用于异步方法调用的库.如果你能做类似的事情会很棒
@async
def longComputation():
<code>
token = longComputation()
token.registerCallback(callback_function)
# alternative, polling
while not token.finished():
doSomethingElse()
if token.finished():
result = token.result()
或者异步调用非异步例程
def longComputation()
<code>
token = asynccall(longComputation())
如果在语言核心中有一个更精细的策略作为本地语言,那就太好了。考虑过吗?
最佳答案
类似:
import threading
thr = threading.Thread(target=foo, args=(), kwargs={})
thr.start() # Will run "foo"
....
thr.is_alive() # Will return whether foo is running currently
....
thr.join() # Will wait till "foo" is done
参见 https://docs.python.org/library/threading.html 上的文档了解更多详情。
https://stackoverflow.com/questions/1239035/
相关文章:
ruby - 即使在使用 rvm pkg install zlib 后也无法加载此类文件 - zli
windows - Microsoft Windows 的终端多路复用器 - GNU Screen
python - 如何使用 Python 将整个文件目录复制到现有目录中?
linux - 如何在 Linux shell 中对变量进行除法?
python - "for line in..."导致 UnicodeDecodeError : '
linux - 如何查看符号链接(symbolic link)的完整绝对路径