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,37 @@ 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+ self .loop = None
884+
885+ def run (self ):
886+ self .loop = qasync .QEventLoop (self )
887+ asyncio .set_event_loop (self .loop )
888+ asyncio .run (self .coro )
889+
890+ def join (self ):
891+ self .loop .stop ()
892+ self .loop .close ()
893+ self .wait ()
894+
895+ event = threading .Event ()
896+
897+ async def coro ():
898+ await asyncio .sleep (0.1 )
899+ event .set ()
900+
901+ thread = CoroutineExecutorThread (coro ())
902+ thread .start ()
903+
904+ assert event .wait (timeout = 1 ), "Coroutine did not execute successfully"
905+
906+ thread .join () # Ensure thread cleanup
907+
908+
877909def teardown_module (module ):
878910 """
879911 Remove handlers from all loggers
You can’t perform that action at this time.
0 commit comments