如何解决将多处理中的全局变量返回到同时运行的另一个函数
这些天我一直在探索python中的多处理和线程。我正在努力解决一个问题: 我有两个函数,并且在两个函数中,我都必须使用多重处理,因为我需要并行传递5个数据帧作为这些函数的输入参数。另外,这两个函数也在Xmins的并行线程中运行,我需要以1min的间隔将5个数据帧从function1传递到function2。架构看起来像这样:
import pandas as pd
import numpy as np
import time
import concurrent.futures
import multiprocessing
pstart=time.time()
list1=[df1,df2,df3,df4,df5]
t_end=time.time()+60*10
def function1(x): ##function1
global df
while t_end> time.time():
""" some computation with x......
........."""
df="""Something dataframe inside the time loop"""
return df
def wokring():
if __name__ == '__main__':
with multiprocessing.Pool(processes=len(sym1)) as p:
results = p.map(function1,sym1). ##this results will yield after 5mins data not imtermediate
def function2(y):
"""some calculation with y"""
return df2 ##returning calculation output
def working2():
global results1
while t_end+ 60*1000 > exchange.milliseconds():
time.sleep(60)
if __name__ == '__main__':
with multiprocessing.Pool(processes=len(???)) as p: ###not sure what to write as arguments here,I need df of first function as input here
results1 = p.map(function2,?????)
with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(wokring) ##thread 1
f2 = executor.submit(working2) ##thread 2
同样在第一个功能中,计时器循环必须连续进行,因为它正在从网站中提取一些实时数据。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。