Why can't you use multiple processes

36 views
Skip to first unread message

li yun

unread,
Feb 22, 2021, 6:29:59 PM2/22/21
to Prometheus Developers
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, please forgive me for not knowing how to format in the google group So I formatted it manually. 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()

Reply all
Reply to author
Forward
0 new messages