Python qyqt multiprocessing questions

Asked 1 weeks ago, Updated 1 weeks ago, 2 views

Hello, there is something I need to do repeatedly through the for statement It's a little slow, so I found out that the Gui program is a multi-process that runs all at once I don't have a clear example, so I'm asking you a question First code is

def GetResult(self):
   self.Loop = threading.Timer(3,self.GetResult) # Retrieves page information every 3 seconds.
        for q in range(0,Lastindex+1): 
         self.getpageinfor(lines[q],self.lineEdit.text())
        self.Loop.start()  

This code keeps getting page information repeatedly as Lastindex + 1 every 3 seconds. For example,

defGetResult(self):
   self.Loop = threading.Timer(3,self.GetResult) # Retrieves page information every 3 seconds.
        for q in range(0,10+1): 
         self.getpageinfor(lines[q],self.lineEdit.text())
        self.Loop.start()  

It goes like thisAnd every three seconds, you're supposed to get 10 pages of information I get 10 pages in order, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and what I want is to use a multi-process, so it pops up from 1 to 10 How can I use such a function in a gui program to use multiprocessing?

python

2022-09-20 11:05

1 Answers

The io operation is not affected by GIL, so you can use multi-thread if you want to get information from the web page.

This is an example of multi-thread based on requests.

import concurrent
import requests

def request_post(url, data):
    return requests.post(url, data=data)

with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
    res = [executor.submit(request_post, url, data) for data in names]
    concurrent.futures.wait(res)


2022-09-20 11:05

If you have any answers or tips


© 2022 pinfo. All rights reserved.