I wanted to be able to show file upload progress for my Python asyncio-based Pushbullet.com library but could not find any obvious solution using aiohttp and tqdm. Here is what I created. Essentially I intercept the calls to reading a file and update the tqdm progress bar accordingly.
The key elements look like this:
def __init__(self, file_path):
self.t = tqdm(desc="Upload",
def read(self, *args, **kwargs):
chunk = super().read(*args, **kwargs)
I finally figured out at least one way to have a Python tkinter app use asyncio event loops, so I thought I should share it. In the end, the solution was simply running an asyncio event loop on another thread. I hope one day Python will merge the two event loops, but for now this works OK.
I have this on pastebin also:
The key points are extracted here:
# Thread that will handle io loop
ioloop = asyncio.new_event_loop()
asyncio.run_coroutine_threadsafe(_connect(), loop=ioloop) # Schedules connection
t = threading.Thread(target=partial(_run, ioloop))
t.daemon = True # won't hang app when it closes
t.start() # Server will connect now