Archipa, when you use the different thread to access same SQLITE
database, do you have any problem? It looks like SQLITE database can
be only accessed by one thread. How do you walk around it?

To all, thanks for your replies, I think my design has some issue.
Massimo's example code and Bill's suggestion made me think I need to
create another process in the background. Tito's suggestion is also
good. but I am so bad at Ajax.

Tommy

On Oct 26, 4:31 pm, achipa <[EMAIL PROTECTED]> wrote:
> Actually, I made a patch that allows execution of code in a parallel
> thread after the page has been served. It can be scheduled (e.g.
> cron), or just launched in a fire and forget fashion without affecting
> the main app and the user (e.g. session cleaning, a long(er)
> conversion task, etc). It runs on all platforms and under both
> mod_wsgi and the stock cherrypy. I sent the patch to Massimo, but I
> have had no response so far, I don't know if he disapproves of the
> patch or simply did not have the time to review it. If there are brave
> souls willing to try it out, I can attach it here, too.
>
> On Oct 26, 9:52 pm, billf <[EMAIL PROTECTED]> wrote:
>
>
>
> > Assuming an event causes the data in the "other" application to change
> > wouldn't it be easier for the "other" application to post the changes
> > to your web2py app when the event occurs?   Having said that, I can
> > envisage a case where there are hundreds or thousands of updates per
> > couple of minutes and you only want a snapsot.
>
> > Looking at Massimo's videotest app, that seems to use the approach of
> > starting a process outside of web2py.  If that is the case then that
> > process could execute a method after an interval that either:
> > a) sends your web2py app a request that causes it to retrieve the data
> > from the "other" application and update the web2py app database, or
> > b) the process gets the data and updates the web2py database directly
> > (unknown to your web2py app that just selects and gets the latest)
>
> > To stop the external process your web2py app could write to the db or
> > a file that is checked by the external process each time it wakes up.
>
> > Admittedly, none of the above explains how to create a background
> > process within web2py - maybe it is just not meant to be done by a
> > mere mortal.
>
> > On Oct 26, 8:01 pm, tommy <[EMAIL PROTECTED]> wrote:
>
> > > Massimo,
>
> > > Here is my code,
>
> > > I use GUI button to start my service (StartEngine, in the background,
> > > I want to retrieve the infomation from another application and save it
> > > in my database for every couple of munites.  after I starting my start
> > > engine service, I can go to other screen. and the background service
> > > keeps runing.
>
> > > I can create the thread now, but got an error :SQLITE object created
> > > in a thread can only used  in that same thread.
>
> > > def enginestart():
> > >     menu_setup()
> > >  #   engine.start()
> > >     session.starttimer=True
>
> > >     symbols=db(db.symbols.id>0).select()
>
> > >    # for symbol in symbols:
> > >    #     engine.addMarket(symbol.symbol_Name,
> > > symbol.description,symbol.tick)
>
> > >     session.flash='engine stared'
> > >     session.enginestarted=True
> > >     db(db.historyprice.id >0).delete()
> > >  #   tt=threading.Timer(2, gethistoryprice(db))
> > >  #   tt.start()
> > >     t=Gethistoryprice()
> > >     t.start()
> > >     redirect(URL(r=request,c='engine',f='enginemaint'))
> > >     return dict()     session.starttimer=True
>
> > >     symbols=db(db.symbols.id>0).select()
>
> > >    # for symbol in symbols:
> > >    #     engine.addMarket(symbol.symbol_Name,
> > > symbol.description,symbol.tick)
>
> > >     session.flash='engine stared'
> > >     session.enginestarted=True
> > >     db(db.historyprice.id >0).delete()
> > >     t=Gethistoryprice(db)
> > >     t.start()
> > >     redirect(URL(r=request,c='engine',f='enginemaint'))
> > >     return dict()
>
> > > class  Gethistoryprice(threading.Thread):
> > >   def __init__(self, db):
> > >          threading.Thread.__init__(self)
>
> > >          self.stopped=0
> > >          self.db=db
>
> > >      def run(self):
> > >        while not self.stopped:
> > >           mysym=self.db(db.symbols.id>0).select()
> > >           for symbol in mysym:
> > >               #  p=engine.getlastprice(symbol)
> > >               p=random.randrange(10.00,60.00)
> > >               now=datetime.datetime.now()
> > >               db.historyprice.insert(symbol_Name=symbol.symbol_Name,
> > > timestamp= now, price=p)
>
> > >      def stop(self):
> > >          self.stopped=1
>
> > > On Oct 26, 2:05 pm, mdipierro <[EMAIL PROTECTED]> wrote:
>
> > > > This app does that. You upload a video and it is converted in
> > > > background (like at youtube) in a separate process (not a thread, a
> > > > process although the process my have threads). The visitor can later
> > > > check the conversion was completed. It includes documentation:
>
> > > >http://mdp.cti.depaul.edu/appliances/default/show/38
>
> > > > Massimo
>
> > > > On Oct 26, 2:00 pm, Keith Edmunds <[EMAIL PROTECTED]> wrote:
>
> > > > > On Sun, 26 Oct 2008 11:55:08 -0700 (PDT), [EMAIL PROTECTED]
> > > > > said:
>
> > > > > > 1) what other background tasks do people envisage?
>
> > > > > A regular display update via Ajax (but that could probably be 
> > > > > demanded by
> > > > > the client rather than pushed)
>
> > > > > > 2) how should you do it in web2py?
>
> > > > > Pass.
>
> > > > > --
> > > > > Keith Edmunds- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to