()
return decorator
Decorator to ensure any method invocations are passed to the main thread
Decorator to ensure any method invocations are passed to the main thread
Decorator to ensure any method invocations are passed to the main thread
def run_in_main_thread():
    """Decorator to ensure any method invocations are passed to the main thread"""

    def decorator(fn):
        def wrapper(*args, **kwargs):
            # Assume the first arg is the 'self', i.e. the bus client
            bus = args[0]

            # We'll provide a queue as the return path for results
            result_queue = janus.Queue()

            # Enqueue the function, it's arguments, and our return path queue
            logger.debug("Adding callable to queue")
            bus._call_queue.sync_q.put((fn, args, kwargs, result_queue))

            # Wait for a return value on the result queue
            logger.debug("Awaiting execution completion")
            result = result_queue.sync_q.get()

            # Cleanup
            bus._call_queue.sync_q.join()  # Needed?
            result_queue.close()

            return result
        return wrapper
    return decorator
def run_in_main_thread ( ) : def decorator ( fn ) : def wrapper ( * args , * * kwargs ) : # Assume the first arg is the 'self', i.e. the bus client bus = args [ 0 ] # We'll provide a queue as the return path for results result_queue = janus . Queue ( ) # Enqueue the function, it's arguments, and our return path queue logger . debug ( "Adding callable to queue" ) bus . _call_queue . sync_q . put ( ( fn , args , kwargs , result_queue ) ) # Wait for a return value on the result queue logger . debug ( "Awaiting execution completion" ) result = result_queue . sync_q . get ( ) # Cleanup bus . _call_queue . sync_q . join ( ) # Needed? result_queue . close ( ) return result return wrapper return decorator