March 27th, 2005, 05:07 PM
Allowing input during a loop
i have a ircbot in which i want it to have a command line interface, the main loops looks something like this:
Of course the problem is that 'raw_input' pauses the loop while it waits for input. How would i go about allowing the loop it run in the background while the program waits for extra input?
NIRC.main_loop( ) #contains the connection to the IRC server
n = raw_input('Enter Bot Commands : ')
if n == 'quit':
March 27th, 2005, 06:01 PM
This seems a very common problem when starting to write any kind of chat program...
- Use an existing IRC-bot and add your own extensions, e.g. supybot, which is really quite good.
- Use something like an event-driven GUI framework which triggers events based on network data arrival, pressing enter on a form, and so on, so you are not manually polling for data.
- Use the Twisted Matrix framework. It is multi-threaded, and handles all sorts of network and internet protocols, including IRC.
- Explicitly write multi-threaded code yourself (but being wary of race and deadlock conditions which can make threaded code awkward to work with and hard to debug). See the modules threading and thread
Last edited by sfb; March 27th, 2005 at 06:11 PM.
March 27th, 2005, 06:26 PM
I would rather not use supybot because the whole purpose (well ,most of it) is to teach myself Python. I'm more interested in options of threads or events, does anyone know of any good tutorials on the topic? Or have another suggestion?