Skip to content

Deadline data type in Python

Task

receive_*timedwait-calls should take a Python datetime object as a deadline parameter and convert this to something PRRT understands.

Code changes:

# prrt.pyx
...
class TimeoutException()
...

cdef class PrrtSocket:
    def __cinit__(self, address, target_delay = 1, thread_pinning = False):
        ...
        self.epoch = epoch = datetime.datetime.utcfromtimestamp(0)

    def recv_*_wait(... deadline: datetime):
        diff = deadline - epoch
        seconds = diff.total_seconds() # DIV/FLOOR
        nanoseconds = diff.totalseconds() # MOD * 1000**3
        cdef timespec deadline_timespec = timespec(seconds, nanoseconds)
        with nogil:
            len = recv()
            if len < 0:
                raise TimeoutException()

API Documentation (https://git.nt.uni-saarland.de/LARN/PRRT/wikis/receive-modes). Examples for calling receive_*_timedwait(...) should be given.

Hints

Edited by Andreas Schmidt