Skip to content
Advertisement

Use tqdm progress bar with asyncio

I am trying to create a single progress bar that will be updated whenever an async task is done.

I have the following code

JavaScript

The above code generates a single progress bar as but it is not updated until all tasks are finished (it shows either 0% or 100% while there’s more than a single task)

I also tried using tqdm.asyncio.tqdm.gather

JavaScript

The above code generates multiple progress bars and as in the previous code block, it shows either 0% or 100%

My starting point was

JavaScript

Would appreciate your help on making it work with a single and dynamic progress bar

Advertisement

Answer

If you call self.pbar.update(1) inside the run_scan scan method after creating concurrent tasks, each task will update the pbar for self. So your class should look like the following

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement