23
23
import contextlib
24
24
import functools
25
25
import importlib
26
+ import inspect
26
27
import itertools
27
28
import logging
28
29
import os
@@ -373,6 +374,7 @@ def run_forever(self):
373
374
374
375
try :
375
376
self .__log_debug ("Starting Qt event loop" )
377
+ asyncio .events ._set_running_loop (self )
376
378
rslt = - 1
377
379
try :
378
380
rslt = self .__app .exec_ ()
@@ -381,6 +383,7 @@ def run_forever(self):
381
383
self .__log_debug ("Qt event loop ended with result %s" , rslt )
382
384
return rslt
383
385
finally :
386
+ asyncio .events ._set_running_loop (None )
384
387
self ._after_run_forever ()
385
388
self .__is_running = False
386
389
@@ -785,8 +788,25 @@ def outer_decorator(fn):
785
788
@Slot (* args , ** kwargs )
786
789
@functools .wraps (fn )
787
790
def wrapper (* args , ** kwargs ):
788
- task = asyncio .ensure_future (fn (* args , ** kwargs ))
789
- task .add_done_callback (_error_handler )
791
+ # Qt ignores trailing args from a signal but python does
792
+ # not so inspect the slot signature and if it's not
793
+ # callable try removing args until it is.
794
+ task = None
795
+ while len (args ):
796
+ try :
797
+ inspect .signature (fn ).bind (* args , ** kwargs )
798
+ except TypeError :
799
+ if len (args ):
800
+ # Only convert args to a list if we need to pop()
801
+ args = list (args )
802
+ args .pop ()
803
+ continue
804
+ else :
805
+ task = asyncio .ensure_future (fn (* args , ** kwargs ))
806
+ task .add_done_callback (_error_handler )
807
+ break
808
+ if task is None :
809
+ raise TypeError ("asyncSlot was not callable from Signal. Potential signature mismatch." )
790
810
return task
791
811
792
812
return wrapper
0 commit comments