星期天快乐.
我想使用多处理模块运行这个代码.但它的作用不仅仅是出于某种原因.
with ProcessPoolExecutor() as executor:
while True:
if LOCAL_RUN:
print("ALERT: Doing a local run of the automation with limited capabilities.")
list_of_clients = db_manager.get_clients()
random.shuffle(list_of_clients)
list_of_not_attempted_clients_domains = db_manager.tags()
group_of_clients_handlers = {}
# no matches
if not list_of_not_attempted_clients_domains:
sleep = 60 * 10
pretty_print(f'No matches found. Sleeping for {sleep}s')
time.sleep(sleep)
continue
for client in list_of_clients:
client_id = client[0]
client_name = client[1]
group_of_clients_handlers[client_id] = [ClientsHandler(db_manager), client_name]
# MULTI-PROCESSING CODE
try:
print('running function...')
executor.map(
partial(run, group_of_clients_handlers=group_of_clients_handlers),
list_of_not_attempted_clients_domains
)
except Exception as err:
print(err)
尽管我try 调试它,但我不知道为什么它不起作用,尽管我觉得这与进程需要时间启动或安排任务等有关,但我不确定.
while循环只是继续运行,我看到所有的print声明都像running function...
一样,但run函数永远不会执行.run函数是一个非常大的函数,具有嵌套的大函数.
except块也不会打印出任何错误.很想听听你的 idea .