Add/Remove Channels in Asyncore?

C

Chris

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?

Thanks,
Chris
 
F

Fredrik Lundh

Chris said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top