lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m24j4cvmlp.fsf@gmail.com>
Date: Tue, 12 Nov 2024 09:16:02 +0000
From: Donald Hunter <donald.hunter@...il.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: netdev@...r.kernel.org,  "David S. Miller" <davem@...emloft.net>,  Eric
 Dumazet <edumazet@...gle.com>,  Paolo Abeni <pabeni@...hat.com>,  Simon
 Horman <horms@...nel.org>,  Xiao Liang <shaw.leon@...il.com>,  Jiri Pirko
 <jiri@...nulli.us>,  donald.hunter@...hat.com
Subject: Re: [PATCH net-next v1 2/2] tools/net/ynl: add async notification
 handling

Jakub Kicinski <kuba@...nel.org> writes:

> 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

I want it to run forever if a duration is not provided, but here
endtime == starttime so it would exit immediately.

I thought the original approach was fairly pythonic - if duration is not
specified (None) then there would be no endtime (None).

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

Yep, thanks. I sketched out roughly this, but using the selectors module
which will use epoll under the covers.

https://docs.python.org/3/library/selectors.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ