#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    8
    Rep Power
    0

    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:

    Code:
        while 1: 
            NIRC.main_loop( ) #contains the connection to the IRC server
            n = raw_input('Enter Bot Commands : ')
            if n == 'quit':
                break
    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    This seems a very common problem when starting to write any kind of chat program...

    Suggestions include:

    - 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 07:11 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    8
    Rep Power
    0
    Originally Posted by sfb
    This seems a very common problem when starting to write any kind of chat program...

    Suggestions include:

    - 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
    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?

IMN logo majestic logo threadwatch logo seochat tools logo