gpt4 book ai didi

python - 线程类型错误: 'module' object is not callable

转载 作者:行者123 更新时间:2023-12-01 01:54:19 26 4
gpt4 key购买 nike

我正在定期运行两个 python 作业。activity_url_collectorstorage_data_collector 是与 index.py 位于同一目录中的 .py 文件。

下面是index.py:

import schedule
import time
import psycopg2
import threading
import activity_url_collector
import storage_data_collector

def main():


def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()

schedule.every(3).minutes.do(run_threaded, activity_url_collector)
schedule.every(3).minutes.do(run_threaded, storage_data_collector)

schedule.run_all()

print('Post-Processing-Application is running')

while True:
schedule.run_pending()
time.sleep(1)

if __name__=="__main__":
main()

详细错误:

Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
TypeError: 'module' object is not callable

这里可能出了什么问题?谢谢。

最佳答案

您正在尝试在线程中运行 activity_url_collectorstorage_data_collector

查看您的导入,两者都是可以由解释器直接运行的模块(Python 文件),但它们不是您的案例所需的“可调用”。

您可以在线程中运行函数、方法或任何实现__call__的对象。作为解决方案,您可以向模块添加一个 main() 函数来执行实际工作,并使用 activity_url_collector.main 作为线程的目标。

关于python - 线程类型错误: 'module' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50384627/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com