Function used in the sending thread of sndrcv()

def _sndrcv_snd(pks, timeout, inter, verbose, tobesent, hsent, timessent, stopevent):  # noqa: E501
    """Function used in the sending thread of sndrcv()"""
    try:
        i = 0
        rec_time = timessent is not None
        if verbose:
            print("Begin emission:")
        for p in tobesent:
            # Populate the dictionary of _sndrcv_rcv
            # _sndrcv_rcv won't miss the answer of a packet that has not been sent  # noqa: E501
            hsent.setdefault(p.hashret(), []).append(p)
            if stopevent.is_set():
                break
            # Send packet
            pks.send(p)
            if rec_time:
                timessent[i] = p.sent_time
            i += 1
            time.sleep(inter)
        if verbose:
            print("Finished sending %i packets." % i)
    except SystemExit:
        pass
    except KeyboardInterrupt:
        pass
    except Exception:
        log_runtime.exception("--- Error sending packets")
    if timeout is not None:
        def _timeout(stopevent):
            stopevent.wait(timeout)
            stopevent.set()
        thread = threading.Thread(
            target=_timeout, args=(stopevent,)
        )
        thread.setDaemon(True)
        thread.start()