asyncore loop and cmdloop problem
Michele Simionato
michele.simionato at gmail.com
Tue May 25 04:55:30 EDT 2010
On May 25, 10:42 am, "kak... at gmail.com" <kak... at gmail.com> wrote:
> Hi to all,
> i'm creating a command line application using asyncore and cmd. At
>
> if __name__ == '__main__':
> import socket
>
> args = sys.argv[1:]
> if not args:
> print "Usage: %s querystring" % sys.argv[0]
> sys.exit(0)
>
> address = ('localhost', 0) # let the kernel give us a port
> server = EchoServer(address)
> ip, port = server.address # find out what port we were given
>
> asyncore.loop()
> CmdClass().cmdloop()
>
> what i want is that the above commands asyncore.loop() and
> CmdClass().cmdloop()
> running at the same time. Meaning that while the application is in cmd
> mode
> with the cmdloop(), it is still able to listen for incoming messages?
> What should i do?
>
> thanks in advance
> A.K.
cmd.Cmd is blocking, so the only way it to run the cmdloop in a
separated thread. Once for fun
I rewrote the cmd module to be non-blocking but if you want to stick
with the standard library you need to use a thread.
More information about the Python-list
mailing list