On Wed, Jan 29, 2014 at 10:50:31PM -0800, Guido van Rossum wrote: > > You most likely shouldn't be doing this. That class is not a complete > implementation, just a base with some parts of the implementation that is > widely shared. The rest of the implementation is in various subclasses whose > name isn't published -- and *which* class is used is determined dynamically at > run time (either by the app or by the event loop policy).
Hurm, gotcha. > There's nothing wrong with your set_event_loop() call, just with your event > loop class... Figured :) > What's the proper way to set the event loop? I really don't want to > re-implement the entire EventLoop class, I just want to add a few > methods for a quirky usecase I have. > > > Does what you want to add *have* to be an event loop method? If you make it a > function that takes a loop argument you don't have to deal with the > subclassing. Yeah. I wanted to allow for something like (sorry, coding in my MUA, I don't know if this even runs, just sketching it out) | class EventedEventLoop(BaseEventLoop): | _handlers = defaultdict(list) | | def add_event_handler(self, event, function): | self._handlers[event].append(function) | | def fire_event(self, event, *args): | for handler in self._handlers[event]: | self.call_soon(handler, *args) So, yeah, I can do this another way, I can just drop that defauldict out and change `self' to `loop' and I'm gold. I hate the syntatic cruft that pops up with that way (looks messier), but I think I might be able to life with myself :) > If you really can't do it any other way, and you really need to inherit from > the event loop, you can inherit from asyncio.SelectorEventLoop, which is an > alias for the real selector-based event loop (the concrete class varies by > platform). But then you won't be supporting IOCP on Windows. And you probably > shouldn't get too comfortable doing that. Yeah, gotcha. I'm sure I'll stumble into something cleaner. Perhaps I'll wrap the `loop' class and see if I can't hide this hackyness away :) > -- > --Guido van Rossum (python.org/~guido) Thanks, Guido! Paul -- #define sizeof(x) rand() </paul> :wq
signature.asc
Description: Digital signature
