Esempio n. 1
0
def _run_test_timeout(test, get_interactive_session, verb=3, my_globals=None):
    """Run a test with timeout"""
    q = queue.Queue()

    def _runner():
        output, res = get_interactive_session(test, verb=verb, my_globals=my_globals)
        q.put((output, res))
    th = threading.Thread(target=_runner)
    th.daemon = True
    th.start()
    th.join(60 * 3)  # 3 min timeout
    if th.is_alive():
        return "Test timed out", False
    return q.get()
Esempio n. 2
0
def autorun_commands_timeout(cmds, timeout=None, **kwargs):
    """
    Wraps autorun_commands with a timeout that raises StopAutorunTimeout
    on expiration.
    """
    if timeout is None:
        return autorun_commands(cmds, **kwargs)

    q = queue.Queue()

    def _runner():
        q.put(autorun_commands(cmds, **kwargs))

    th = threading.Thread(target=_runner)
    th.daemon = True
    th.start()
    th.join(timeout)
    if th.is_alive():
        raise StopAutorunTimeout
    return q.get()
Esempio n. 3
0
 def __init__(self, *args, **kwargs):
     super(SocketWrapper, self).__init__(*args, **kwargs)
     self.rx_queue = queue.Queue()  # type: queue.Queue[can_Message]
     self.name = None
     SocketsPool().register(self, *args, **kwargs)
Esempio n. 4
0
    def __init__(
            self,
            can_socket,  # type: "CANSocket"
            src_id,  # type: int
            dst_id,  # type: int
            padding=False,  # type: bool
            extended_addr=None,  # type: Optional[int]
            extended_rx_addr=None,  # type: Optional[int]
            rx_block_size=0,  # type: int
            rx_separation_time_min=0,  # type: int
            listen_only=False  # type: bool
    ):
        # type: (...) -> None
        self.can_socket = can_socket
        self.dst_id = dst_id
        self.src_id = src_id
        self.padding = padding
        self.fc_timeout = 1
        self.cf_timeout = 1

        self.filter_warning_emitted = False

        self.extended_rx_addr = extended_rx_addr
        self.ea_hdr = b""
        if extended_addr is not None:
            self.ea_hdr = struct.pack("B", extended_addr)
        self.listen_only = listen_only

        self.rxfc_bs = rx_block_size
        self.rxfc_stmin = rx_separation_time_min

        self.rx_queue = queue.Queue()
        self.rx_len = -1
        self.rx_buf = None  # type: Optional[bytes]
        self.rx_sn = 0
        self.rx_bs = 0
        self.rx_idx = 0
        self.rx_ts = 0.0  # type: Union[float, EDecimal]
        self.rx_state = ISOTP_IDLE

        self.txfc_bs = 0
        self.txfc_stmin = 0
        self.tx_gap = 0

        self.tx_buf = None  # type: Optional[bytes]
        self.tx_sn = 0
        self.tx_bs = 0
        self.tx_idx = 0
        self.rx_ll_dl = 0
        self.tx_state = ISOTP_IDLE

        self.tx_timeout_handle = None  # type: Optional[TimeoutScheduler.Handle]  # noqa: E501
        self.rx_timeout_handle = None  # type: Optional[TimeoutScheduler.Handle]  # noqa: E501
        self.rx_thread = CANReceiverThread(can_socket, self.on_can_recv)

        self.tx_mutex = Lock()
        self.rx_mutex = Lock()
        self.send_mutex = Lock()

        self.tx_done = Event()
        self.tx_exception = None  # type: Optional[str]

        self.tx_callbacks = []  # type: List[Callable[[], None]]
        self.rx_callbacks = []  # type: List[Callable[[bytes], None]]

        self.rx_thread.start()