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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---