From: kaklis on
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.
From: Michele Simionato on
On May 25, 10:42 am, "kak...(a)gmail.com" <kak...(a)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.
From: kaklis on
On May 25, 4:55 am, Michele Simionato <michele.simion...(a)gmail.com>
wrote:
> On May 25, 10:42 am, "kak...(a)gmail.com" <kak...(a)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.

Thank you so much.
Is there a way that i can find that version of cmd?

Antonis

From: Giampaolo Rodolà on
2010/5/25 Michele Simionato <michele.simionato(a)gmail.com>:
> On May 25, 10:42 am, "kak...(a)gmail.com" <kak...(a)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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Too bad cmdloop() doesn't provide an argument to return immediately.
Why don't you submit this patch on the bug tracker?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
From: Michele Simionato on
On May 25, 12:03 pm, Giampaolo Rodolà <g.rod...(a)gmail.com> wrote:
> Too bad cmdloop() doesn't provide an argument to return immediately.
> Why don't you submit this patch on the bug tracker?
>
> --- Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil

Because it is not a bug, cmd was designed to be blocking. It would be
a feature request.
I wrote a cmd2 module a few years ago, which was intended as a
replacement for cmd with various
additional features (including the non blocking behavior). We are
using it in production, but I
have never published it (I intended to but, you know, a days has only
24 hours ;)
I should put together the code in a single file and publish it, but I
cannot guarantee if and when I will have the time to do so.