Hello everyone, there is a small program (online store parser), I decided to give it an appearance, and also added the ProgressBar . My problem is that I do not know how to make ProgressBar work in parallel during parsing. As a result, I realized that it is necessary to launch the ProgressBar in a separate thread, but so far I have difficulty in implementing this process. I thought that it would be possible to somehow start two processes at once, when one button was pressed, but it did not work out.

 def launch_bar(self, instance): self.pb = ProgressBar() popup = Popup(title="In process", content=self.pb, size_hint=(0.7,0.3)) popup.open() Clock.schedule_interval(self.go,1) def go(self, instance): self.pb.value += 1 

This is all relative to the ProgressBar .
Thank you in advance for your response

    1 answer 1

    Parsing runs in a separate thread, not a progress bar. The fact is that the interface element is not blocking, but parsing is blocking.

    On the progress bar hangs a timer that looks at the variable with the number of pages or whatever you have. The interface runs in the main thread.

    Processing is started by the button in the new thread. In most cases, it is not necessary to invent anything new except for this pointer, the timer to itself:

     def process(data,progress): .... progress[0]+=1 ..... progress = [0] t = Thread(target=process,args=(data,progress)) t.start() events=[] def tick(t): if t.is_alive(): t.join(timeout=0.5) print(progress[0]) else: event.cancel() ev = Clock.schedule_interval(partial(tick, t, events), 1) events.append(ev) t.start() 

    I also love multiprocessing.Pool().map(...) , but with this option the progress variable should be from multiprocessing.manager. With threads or a variable, you bind to the context (self.progress, global progress) or the changeable type is passed as a parameter.

    • Many thanks, I will try - Karlson21