File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66import asyncio
77import ctypes
8+ import threading
89import logging
910import multiprocessing
1011import os
@@ -874,6 +875,30 @@ async def main():
874875 assert not loop .is_running ()
875876
876877
878+ def test_qeventloop_in_qthread ():
879+ class CoroutineExecutorThread (qasync .QtCore .QThread ):
880+ def __init__ (self , coro ):
881+ super ().__init__ ()
882+ self .coro = coro
883+
884+ def run (self ):
885+ asyncio .set_event_loop (qasync .QEventLoop (self ))
886+ asyncio .run (self .coro )
887+
888+ event = threading .Event ()
889+
890+ async def coro ():
891+ await asyncio .sleep (0.1 )
892+ event .set ()
893+
894+ thread = CoroutineExecutorThread (coro ())
895+ thread .start ()
896+
897+ assert event .wait (timeout = 1 ), "Coroutine did not execute successfully"
898+
899+ thread .wait () # Ensure thread cleanup
900+
901+
877902def teardown_module (module ):
878903 """
879904 Remove handlers from all loggers
You can’t perform that action at this time.
0 commit comments