并行采集数据,制作lis

2024-06-16 11:25:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我的申请有效。它检查心脏监护仪的健康状况(由具有ID的医生监督),并收集医生当前的活动。下面我将展示我编写的部分代码(在ubuntu中使用python)。但是我想要的是:

  • 我们收到用户在Web浏览器中填写的ID(医生的ID)
  • 然后并行执行2个活动:我们收集健康评分,第二个活动可以并行进行,因为我们已经知道医生的ID:我们可以在此时自动检查医生的活动。你知道吗
  • 我列了一个清单,把这些分数合并在一起。你知道吗

如何使代码并行?这两台服务器相互独立。因为现在我要等到我拿到炉边的监护仪,然后医生才知道它在活动。在请求之前我做了一些搜索操作,请求之后我做了一些繁重的计算,所以我在寻找一种并行编程/CPU密集型的解决方案。你知道吗

@app.route('/getstatus',methods=['POST','GET'])
def get_score():
    if request.method=='POST':
    #we wait till the web user has filled in the ID of the doctor
        id = request.form['id']

        #hearthmonitor Processor 1 parallelactivity 1 before the request I am searching the servername of the hearthmonitor that belongs with the ID
        urlhearth=serverhearth+id
        rh= requests.get(serverhearth, allow_redirects=False)
        h1=rh.content


        #doctormonitor Processor 2 parallelactivity 2 before the request I am searching the servername of the doctorserver (department server) that belongs with the ID. This is what I want to run in parrallel with activity 1   
        urldoc=server+id
        rd= requests.get(urldoc, allow_redirects=False)
        d1= rd.content



        #we make a list of their outcomes together
        list=[doctor, hearth]

Tags: ofthe代码inidgetrequestwith