我想重复请求服务器,该服务器将返回一些任务。服务器的响应将是字典,其中包含需要调用的功能列表。例如:
{
tasks: [
{
function: "HelloWorld",id: 1212
},{
function: "GoodbyeWorld"
id: 1222
}
]
}
注意:我正在淡化它。
对于每个任务,我将使用multiprocessing
运行指定的函数。这是我的代码示例:
r = requests.get('https://localhost:5000',auth=('user','pass'))
data = r.json()
if len(data["tasks"]) > 0:
manager = multiprocessing.Manager()
for task in data["tasks"]:
if task["function"] == "HelloWorld":
helloObj = HelloWorldClass()
hello = multiprocessing.Process(target=helloObj.helloWorld)
hello.start()
hello.join()
elif task["function"] == "GoodbyeWorld":
byeObj = GoodbyeWorldClass()
bye = multiprocessing.Process(target=byeObj.byeWorld)
bye.start()
bye.join()
问题是,我想重复发出请求,并在其他进程正在运行时填充data["tasks"]
数组。如果我将所有内容都放入某个while
循环中,那么它只会在初始响应的所有过程完成后(所有过程都达到join()
时才发出请求)。
有人可以帮助我重复请求并连续填充数组吗?请让我知道是否需要澄清。