我目前在 2 个 python 文件中有 2 个函数。第一个看起来像(称为file1.py)
import threading
from file2 import main_task
gotime = threading.Event()
thread1 = threading.Thread(target=main_task)
thread1.start()
input()
gotime.set()
第二个(file2.py)看起来像:
import threading
def main_task():
print('Waiting!')
gotime.wait()
print('Event has bet triggered!')
现在当我运行它时,我得到
NameError: name 'gotime' is not defined
所以我尝试通过将 gotime 导入 file2py 来修复它,如下所示:
from file1 import gotime
但是在运行之后,我得到了
ImportError: cannot import name 'main_task' from 'file2' (/my/dir/file2.py)
有想法该怎么解决这个吗?谢谢!