Yeah I have used it quite a bit already to control other programs in the server administration webinterface I'm making with web2py. Catching all possible responses (by that i mean like if you try something and the program you control tells you something) and handle them is really most of the work when you execute a command.
What I did notice is that the pxssh.py module, specially build to handle ssh sessions does give troubles when its being controlled from web2py (nonblockingread timeouts even if I set them much higher). Not that it matters that much since it's still easy enough to do it in pexpect itself. Overall it works, though when controlled from web2py there are a few little quirks (like having to store the spawned child in the cache), but nothing spectacular. On Nov 18, 10:58 pm, mdipierro <[EMAIL PROTECTED]> wrote: > I am checking pexpect. It is fantastic. It is really easy to integrate > in web2py because it is a single file. Too bad does not work on > windows. Anyway, this really opens the door to a lot interesting > applications. > > Massimo > > On Nov 17, 2:21 pm, mdipierro <[EMAIL PROTECTED]> wrote: > > > I mean actual process, not session. You run into problems if you start > > two instances of web2py on the same machine or on different machines. > > > Also mind that the cache uses the filename as key (first argument of > > cache.ram) to retrieve the file. You may want the key dependent on the > > response.session_id if you have one file per session. That depends on > > details. > > > Massimo > > > On Nov 17, 2:16 pm, artien <[EMAIL PROTECTED]> wrote: > > > > Thanks the cache.ram works :) One process running web2py do you mean > > > as in actual processes or as in sessions? > > > > Artien > > > > On Nov 17, 8:00 pm, mdipierro <[EMAIL PROTECTED]> wrote: > > > > > You are trying to create a process from one action (one http request) > > > > and access it from another one. This is what pexpect is for. > > > > I have neve used it before. The problem is that objects create in one > > > > request are not persistant unless you say do. > > > > > There are two mechanisms for persistance: session and cache. > > > > > 1) try session > > > > > def do_file(param1): > > > > if param1 == 'create': > > > > session.child=pexpect.spawn('nano -wc myfile.txt') > > > > else: > > > > session.child.sendline(param1) > > > > session.child.close() > > > > > will work if and only if child is pickable else you will get an error. > > > > > 2) try cache.ram > > > > > def do_file(param1): > > > > if param1 == 'create': > > > > filename='myfile.txt' > > > > child=cache.ram(filename,lambda:pexpect.spawn('nano -wc > > > > '+filename),0) #update cache > > > > else: > > > > # retrieve from cache without expiration > > > > child=cache.ram(filename,lambda:None,10**10) #cache forver > > > > child.sendline(param1) > > > > child.close() > > > > > this will work as long as you have only one process running web2py. > > > > > On Nov 17, 12:26 pm, artien <[EMAIL PROTECTED]> wrote: > > > > > > Hello, > > > > > > I'm trying to use pexpect from web2py with limited success. What I > > > > > notice is that web2py doesn't treat the object like a normal python > > > > > program would. > > > > > > A simple example (my real program creates ssh sessions this is just to > > > > > demonstrate the issue): > > > > > > with ajax I call two functions: > > > > > > first it calls > > > > > def open_file(): > > > > > do_file('create') > > > > > message = 'created' > > > > > return dict(message=message) > > > > > > then it calls > > > > > def data_file(): > > > > > info =request.vars.values()[0] > > > > > do_file('hello this program is crap) > > > > > message = 'stored info into file' > > > > > return dict(message=mesage) > > > > > > Then we have the controller function which does it > > > > > > def do_file(param1): > > > > > if param1 == 'create': > > > > > child=pexpect.spawn('nano -wc myfile.txt') > > > > > else: > > > > > child.sendline(param1) > > > > > child.close() > > > > > > Now it says that the second time: > > > > > > UnboundLocalError: local variable 'child' referenced before assignment > > > > > > When I try to store the child object in a session variable I get the > > > > > error that it can't store file objects. > > > > > > Is there anyway I can make web2py keep its reference to the object so > > > > > I can keep using it? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---