[英]How to make a python function from another python file run as an independent process?
所以我想這樣做,假設有 2 個 python 文件 A.py 和 B.py。
py
import B
some_code
.
.
.
function_of_B.py()
rest_of_the_code
我遇到的問題是rest_of_the_code
等待function_of_B.py()
完成執行,我想要的是function_of_B.py()
並行執行或獨立於A.py 執行,這樣rest_of_the_code
可以在不等待function_of_B.py()
完成。
使用多線程:
import B
import threading
some_code
threading.Thread(target=B.function_of_B).start()
rest_of_the_code
您可以使用:
print("this thread executed by",threading.current_thread().getName())
在 B.py 和 A.py 中獲取當前線程名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.