Beispiel #1
0
def _callAndWaitFor(function, *args, timeout=None, **kwargs):
    """
    Call a method containing an Event and wait for completion.
    :param function: Method with ability to call a callback to set a event.
    :param args: User arguments.
    :param timeout: Time in sec to wait for method to complete.
    :param kwargs: User arguments.
    :return: Event message.
    """
    event = Event()
    event.message = None
    function(functools.partial(_callback, event), *args, **kwargs)
    event.wait(timeout=timeout)
    return event.message
Beispiel #2
0
 def __send(msg_obj, timeout=10, callback=None, block=True) -> Message:
     """
     Send messages to the SEPL platform.
     :param msg_obj: Message object.
     :param timeout: Timeout in sec.
     :param callback: Method to be called on response or timeout.
     :param block: Boolean, set to False for asynchronous behavior.
     :return: Message object.
     """
     msg_str = marshalMsg(msg_obj)
     token = getMangledAttr(msg_obj, 'token')
     if block:
         event = Event()
         event.message = None
         callback = functools.partial(_callback, event)
         SessionManager.new(msg_obj, token, timeout, callback)
         __class__.__out_queue.put(msg_str)
         event.wait()
         return event.message
     else:
         SessionManager.new(msg_obj, token, timeout, callback)
         __class__.__out_queue.put(msg_str)