Add/Remove Channels in Asyncore?
Fredrik Lundh
fredrik at pythonware.com
Sat Dec 23 11:41:21 EST 2006
Chris wrote:
> I've implemented a real basic IRC client class in 100 lines using
> asynchat (yes I know about Twisted). The problem I'm having is
> arbitrarily starting and stopping multiple instances of this class
> after I call loop().
>
> The asyncore docs seem to imply everything's fixed in stone once loop()
> is called, where they say, "Once the initial channel(s) is(are)
> created, calling the loop() function activates channel service, which
> continues until the last channel (including any that have been added to
> the map during asynchronous service) is closed."
>
> After I call asyncore.loop(), I'd like to be able to add/remove clients
> ("channels"?) to/from execution by asyncore. Is this possible?
the usual way to do that is to add new channels in callbacks, in
response to other server activities.
if you want to deal with this from the program calling asyncore.loop,
use the "count" option to tell loop to return after N events. e.g:
while 1:
asyncore.loop(0.05, count=20) # wait for max 1 second
add/remove channels here
</F>
More information about the Python-list
mailing list