event-loop

Calling asyncio.run_coroutine_threadsafe across different event loops

Calling asyncio.run_coroutine_threadsafe across different event loops Question: I have a class inside a microservice that looks like this: import asyncio import threading class A: def __init__(self): self.state = [] self._flush_thread = self._start_flush() self.tasks = set() def _start_flush(self): threading.Thread(target=self._submit_flush).start() def _submit_flush(self): self._thread_loop = asyncio.new_event_loop() self._thread_loop.run_until_complete(self.flush_state()) # async def regular_func(self): # This function is called on an …

Total answers: 2

Event loop is not stopped after calling stop() method using python asyncio module

Event loop is not stopped after calling stop() method using python asyncio module Question: I have written the following code: import asyncio import time from threading import Thread from threading import Timer async def myCouroutine(): time.sleep(3) dbAccessLoop = None def stopEventLoop(): dbAccessLoop.stop() def eventLoopThreadMain(): global dbAccessLoop try: dbAccessLoop = asyncio.new_event_loop() dbAccessLoop.run_forever() finally: dbAccessLoop.close() def main(): …

Total answers: 1

root.iconbitmap() forces tkinter to enter a temporary eventloop?

root.iconbitmap() forces tkinter to enter a temporary eventloop? Question: Does wm_iconbitmap method forces tkinter to enter an event loop while it processes the icon file? Is there a way to avoid this? Check this example that illustrates this: from tkinter import * import time root = Tk() root.iconbitmap(‘images/logo.ico’) # Without `mainloop()` shows the window, means …

Total answers: 1

asyncio: Is it possible to cancel a future been run by an Executor?

asyncio: Is it possible to cancel a future been run by an Executor? Question: I would like to start a blocking function in an Executor using the asyncio call loop.run_in_executor and then cancel it later, but that doesn’t seem to be working for me. Here is the code: import asyncio import time from concurrent.futures import …

Total answers: 2

Tkinter: How to use threads to preventing main event loop from "freezing"

Tkinter: How to use threads to preventing main event loop from "freezing" Question: I have a small GUI test with a “Start” button and a Progress bar. The desired behavior is: Click Start Progressbar oscillates for 5 seconds Progressbar stops The observed behavior is the “Start” button freezes for 5 seconds, then a Progressbar is …

Total answers: 5

How would you implement a basic event-loop?

How would you implement a basic event-loop? Question: If you have worked with gui toolkits, you know that there is a event-loop/main-loop that should be executed after everything is done, and that will keep the application alive and responsive to different events. For example, for Qt, you would do this in main(): int main() { …

Total answers: 7