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

From: Jakub Kicinski <[email-masked]>
Date: Mon, 11 Nov 2024 10:03:25 -0800

On Mon, 11 Nov 2024 11:06:18 +0000 Donald Hunter wrote:
> > 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 ?

I was suggesting:

	def poll_nft([...], duration=0)

	endtime = time.time() + duration

> >> +        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.

I thought select is pretty trivial to use in python, basically:

	sock, _, _ = select.select([sock], [], [], timeout=to)
	if sock:
		handle_sock()
	to = endtime - time.time()
	if to <= 0:
		return