Subject: Re: [PATCH net-next v1 2/2] tools/net/ynl: add async notification handling

From: Donald Hunter <[email-masked]>
Date: Mon, 11 Nov 2024 11:06:18 +0000

Jakub Kicinski <[email-masked]> writes:

> On Fri,  8 Nov 2024 12:38:16 +0000 Donald Hunter wrote:
>> +    def poll_ntf(self, interval=0.1, duration=None):
>> +        endtime = time.time() + duration if duration else None
>
> could we default duration to 0 and always check endtime?
> I think we can assume that time doesn't go back for simplicity

I don't follow; what are you suggesting I initialise endtime to when
duration is 0 ?

>> +        while True:
>> +            try:
>> +                self.check_ntf()
>> +                yield self.async_msg_queue.get_nowait()
>> +            except queue.Empty:
>> +                try:
>> +                    time.sleep(interval)
>
> Maybe select or epoll would be better that periodic checks?

This was the limit of my python knowledge TBH. I can try using python
selectors but I suspect periodic checks will still be needed to reliably
check the endtime.

>> +                except KeyboardInterrupt:
>> +                    return
>> +            if endtime and endtime < time.time():
>> +                return