I try to perform multi-process analysis in the code to analyze the data of a certain file, but the code cannot perform the join normally, and there is no method to perform multiprocessing.Process. May I ask what I did wrong. Thank you very much for reading my question. Below is my test code
#coding:utf-8
from prometheus_client import generate_latest, CollectorRegistry
from prometheus_client.core import CollectorRegistry
from flask import Response,Flask
import multiprocessing
class CustomCollector(object):
def get_data(self,data):
print(data)
def collect(self):
plist = []
for x in range(30):
p = multiprocessing.Process(target=self.get_data,args=("test",))
plist.append(p)
p.start()
for p in plist:
p.join()
print('Process close')
def rundata():
REGISTRY = CollectorRegistry(auto_describe=False)
REGISTRY.register(CustomCollector())
coll = CustomCollector()
coll.collect()
return Response(generate_latest(REGISTRY), mimetype="text/plain")
rundata()
Read more here: https://stackoverflow.com/questions/66325465/prometheus-client-why-cant-you-use-multiple-processes
Content Attribution
This content was originally published by user51679 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.