Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Nick Badger
Quick preface: there are definitely times when code "smell" really isn't -- nothing's perfect! -- and sometimes some system component is unavoidably inelegant. I think this is oftentimes (but not always) the result of scoping: clearly I couldn't decide, as a library author, that "it's all just brok

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Nathaniel Smith
On Sun, Jan 14, 2018 at 2:45 PM, Nick Badger wrote: >> However, I think this is probably a code smell. Like all code smells, >> there are probably cases where it's the right thing to do, but when >> you see it you should stop and think carefully. > > Huh. That's a really good point. But I'm not su

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Nathaniel Smith
On Sun, Jan 14, 2018 at 5:11 AM, Chris Jerdonek wrote: > On Sun, Jan 14, 2018 at 3:33 AM, Nathaniel Smith wrote: >> On Fri, Jan 12, 2018 at 4:17 AM, Chris Jerdonek >> wrote: >>> Say you have a complex operation that you want to be able to timeout >>> or cancel, but the process of cleanup / cance

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Dima Tisnek
I suppose the websocket case ought to follow conventions similar to kernel TCP API where `close` returns immediately but continues to send packets behind the scenes. It could look something like this: with move_on_after(10): await get_ws_message(url): async def get_ws_message(url): async

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Nick Badger
> > However, I think this is probably a code smell. Like all code smells, > there are probably cases where it's the right thing to do, but when > you see it you should stop and think carefully. Huh. That's a really good point. But I'm not sure the source of the smell is the code that needs the sh

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Chris Jerdonek
On Sun, Jan 14, 2018 at 3:33 AM, Nathaniel Smith wrote: > On Fri, Jan 12, 2018 at 4:17 AM, Chris Jerdonek > wrote: >> Say you have a complex operation that you want to be able to timeout >> or cancel, but the process of cleanup / cancelling might also require >> a certain amount of time that you'

Re: [Async-sig] Blog post: Timeouts and cancellation for humans

2018-01-14 Thread Nathaniel Smith
On Fri, Jan 12, 2018 at 4:17 AM, Chris Jerdonek wrote: > Thanks, Nathaniel. Very instructive, thought-provoking write-up! > > One thing occurred to me around the time of reading this passage: > >> "Once the cancel token is triggered, then all future operations on that >> token are cancelled, so t