当我调用my_batch.run_jobs()
时,我的线程不会在后台运行。相反,它通过等待方法完成运行来同步运行
对于上下文,我从.py
文件中调用此方法,并且该方法在类中。当我在这个文件/类之外运行相同的函数时,它会在后台正常运行
# package_name/module_name.py
class BaseModel(Model):
class Meta:
database = get_db()
class Batch(BaseModel):
def run_jobs():
def sleeper():
sleep(999)
t = threading.Thread(target=sleeper)
#t.daemon = True #tried with/ without
t.start()
比如说
my_batch = Batch()
my_batch.run_jobs()
#doesn't print until line above finishes
print("in progress")
我更新了你的测试代码。它似乎按预期运行
输出
-更新-
以下是相同的代码,分为模块:
迈克·皮
threadchk.py(主脚本)
输出与上一次运行相同
相关问题 更多 >
编程相关推荐