[Python-ideas] Async API: some code to review
Yury Selivanov
yselivanov.ml at gmail.com
Tue Oct 30 03:18:25 CET 2012
On 2012-10-29, at 10:07 PM, Guido van Rossum <guido at python.org> wrote:
[...]
>> 5. For epoll you probably want to check/(log?) EPOLLHUP and EPOLLERR errors
>> too.
>
> Do you have a code sample? I haven't found a need yet.
Just a code dump from my epoll proactor:
if ev & EPOLLHUP:
sock.close(_error_cls=ConnectionResetError)
self._unschedule(fd)
continue
if ev & EPOLLERR:
sock.close(_error_cls=ConnectionError, _error_msg='socket error in epoll proactor')
self._unschedule(fd)
continue
[...]
>> It would be even better if we can return
>> a tiny wrapper, that lets you to simply write 'doit.run().with_timeout(2.1)',
>> instead of:
>>
>> task = scheduling.Task(doit(), timeout=2.1)
>> task.start()
>> scheduling.run()
>
> The run() call shouldn't be necessary unless you are at the toplevel.
Yes, that's just a sugar to make top-level runs more appealing.
You'll also get a nice way of setting timeouts,
yield from coro().with_timeout(1.0)
[...]
>> I also liked the simplicity of the Task class. I think it'd be easy
>> to mix greenlets in it by switching in a new greenlet on each 'step'.
>> That will give you 'yield_()' function, which you can use in the same
>> way you use 'yield' statement now (I'm not proposing to incorporate
>> greenlets in the lib itself, but rather to provide an option to do so)
>> Hence there should be a way to plug your own Task (sub-)class in.
>
> Hm. Someone else will have to give that a try.
I'll be that someone once we choose the direction ;) IMO the greenlets
integration is a very important topic.
-
Yury
More information about the Python-ideas
mailing list