python - 在 Python 中,我可以在一开始就启动一个后台工作程序,进行一些计算,然后在同一个函数结束时等待它的结果吗?
问题描述
在 Python 中,如何在函数的开头启动一个进程/工作者并在最后等待它?就像是:
def my_function():
worker_ref = start_long_computation()
local_result = do_heavy_computations()
return worker_ref.wait_for_result() or local_result
这样,wait_for_result()
如果结果已在start_long_computation()
和之间处理,则可能会立即返回do_heavy_computations()
。
解决方案
推荐阅读
- apache-kafka - Kafka SASL_PLAINTEXT 与 GSSAPI for kerberos
- java - 如何使用java在用户系统中打开excel文件
- python - 在 Keras 模型中向 Conv1D 层提供输入时出错
- azure - 如何使用 ADF V1 将数据插入计算列
- javascript - 使用 LocalStorage 时 Javascript 幻灯片无法正常工作
- python - Grok Python Word 计数器
- scala - 通过将键中的值覆盖为redis列表来编写spark数据帧
- bash - 将传感器输出提取到排序数组中
- java - 科尔多瓦构建问题 - javac - 版本无法运行
- python - 迭代和词形化列表