|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
run cherrypy with my own main loop?Hi, I'd like to run cherrypy, and keep my main loop... is this possible? eg, import cherrypy class HelloWorld(object): def index(self): return "Hello World!" index.exposed = True cherrypy.quickstart(HelloWorld()) # returns here, rather than running forever. while 1: # do my own stuff do_my_stuff_here = 1 # this is the method I want to know about? cherrypy.iterate() Or maybe I can run cherrypy is a separate thread somehow? cheers, --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?Cherrypy already runs in a separate thread, so you can do this. Here is an example using CP 3.1, if you're using an older version of CherryPy there may be a few other steps aside from mounting the application and telling the engine to start.: import cherrypy class HelloWorld(object): def index(self): return "Hello World!" index.exposed = True cherrypy.tree.mount(HelloWorld(), "/") cherrypy.engine.start() # Put your main loop in a try finally to ensure that we tell # cherrypy to stop when we're done (even if we have an unhandled exception). # This is important, or it will hang your process when your # application doesn't exit properly. try: for x in range(15): print "doing my own main loop", x import time time.sleep(1) # sleep so that we can confirm the server is running finally: print "I'm done, and am now exiting." cherrypy.engine.stop() Lakin On Mon, Jun 2, 2008 at 10:59 PM, illume <renesd@...> wrote: > > Hi, > > I'd like to run cherrypy, and keep my main loop... is this possible? > > eg, > > import cherrypy > > class HelloWorld(object): > def index(self): > return "Hello World!" > index.exposed = True > > cherrypy.quickstart(HelloWorld()) > # returns here, rather than running forever. > > while 1: > # do my own stuff > do_my_stuff_here = 1 > > # this is the method I want to know about? > cherrypy.iterate() > > > Or maybe I can run cherrypy is a separate thread somehow? > > > > cheers, > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?hi, thank you. cherrypy.engine.start(blocking=False) is how you get it to not block in 3.0. It looks like the API is broken for cherrypy.engine.start(blocking = False) in 3.1 cu, On Jun 4, 12:55 am, "Lakin Wecker" <lakin.wec...@...> wrote: > Cherrypy already runs in a separate thread, so you can do this. Here > is an example using CP 3.1, if you're using an older version of > CherryPy there may be a few other steps aside from mounting the > application and telling the engine to start.: > import cherrypy > > class HelloWorld(object): > def index(self): > return "Hello World!" > index.exposed = True > > cherrypy.tree.mount(HelloWorld(), "/") > cherrypy.engine.start() > > # Put your main loop in a try finally to ensure that we tell > # cherrypy to stop when we're done (even if we have an unhandled exception). > # This is important, or it will hang your process when your > # application doesn't exit properly. > try: > for x in range(15): > print "doing my own main loop", x > import time > time.sleep(1) # sleep so that we can confirm the server is running > > finally: > print "I'm done, and am now exiting." > cherrypy.engine.stop() > > Lakin > > On Mon, Jun 2, 2008 at 10:59 PM, illume <ren...@...> wrote: > > > Hi, > > > I'd like to run cherrypy, and keep my main loop... is this possible? > > > eg, > > > import cherrypy > > > class HelloWorld(object): > > def index(self): > > return "Hello World!" > > index.exposed = True > > > cherrypy.quickstart(HelloWorld()) > > # returns here, rather than running forever. > > > while 1: > > # do my own stuff > > do_my_stuff_here = 1 > > > # this is the method I want to know about? > > cherrypy.iterate() > > > Or maybe I can run cherrypy is a separate thread somehow? > > > cheers, You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?illume wrote: > cherrypy.engine.start(blocking=False) is how you get it to not block > in 3.0. > > It looks like the API is broken for cherrypy.engine.start(blocking = > False) in 3.1 Not broken, just different. In 3.1 you make two calls: engine.start(), then engine.block(). That change was made in part to make what you're doing more explicit, not to mention more obvious that the feature is both there and desirable. Robert Brewer fumanchu@... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?The API has changed, yes. I don't think it's broken. Lakin On Tue, Jun 3, 2008 at 5:26 PM, illume <renesd@...> wrote: > > hi, > > thank you. > > cherrypy.engine.start(blocking=False) is how you get it to not block > in 3.0. > > It looks like the API is broken for cherrypy.engine.start(blocking = > False) in 3.1 > > cu, > > > On Jun 4, 12:55 am, "Lakin Wecker" <lakin.wec...@...> wrote: >> Cherrypy already runs in a separate thread, so you can do this. Here >> is an example using CP 3.1, if you're using an older version of >> CherryPy there may be a few other steps aside from mounting the >> application and telling the engine to start.: >> import cherrypy >> >> class HelloWorld(object): >> def index(self): >> return "Hello World!" >> index.exposed = True >> >> cherrypy.tree.mount(HelloWorld(), "/") >> cherrypy.engine.start() >> >> # Put your main loop in a try finally to ensure that we tell >> # cherrypy to stop when we're done (even if we have an unhandled exception). >> # This is important, or it will hang your process when your >> # application doesn't exit properly. >> try: >> for x in range(15): >> print "doing my own main loop", x >> import time >> time.sleep(1) # sleep so that we can confirm the server is running >> >> finally: >> print "I'm done, and am now exiting." >> cherrypy.engine.stop() >> >> Lakin >> >> On Mon, Jun 2, 2008 at 10:59 PM, illume <ren...@...> wrote: >> >> > Hi, >> >> > I'd like to run cherrypy, and keep my main loop... is this possible? >> >> > eg, >> >> > import cherrypy >> >> > class HelloWorld(object): >> > def index(self): >> > return "Hello World!" >> > index.exposed = True >> >> > cherrypy.quickstart(HelloWorld()) >> > # returns here, rather than running forever. >> >> > while 1: >> > # do my own stuff >> > do_my_stuff_here = 1 >> >> > # this is the method I want to know about? >> > cherrypy.iterate() >> >> > Or maybe I can run cherrypy is a separate thread somehow? >> >> > cheers, > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?cool. here's a work around for the api change... if you want it to work with different versions of cherrypy. def engine_block(engine): if hasattr(engine.block): engine.block() else: engine.start(blocking=True) def engine_start(engine): if hasattr(engine.block): engine.start() else: engine.start(blocking=False) cheers, On Jun 4, 9:46 am, "Robert Brewer" <fuman...@...> wrote: > illume wrote: > > cherrypy.engine.start(blocking=False) is how you get it to not block > > in 3.0. > > > It looks like the API is broken for cherrypy.engine.start(blocking = > > False) in 3.1 > > Not broken, just different. In 3.1 you make two calls: engine.start(), > then engine.block(). That change was made in part to make what you're > doing more explicit, not to mention more obvious that the feature is > both there and desirable. > > Robert Brewer > fuman...@... You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: run cherrypy with my own main loop?... and updated to actually work. def engine_block(engine): if hasattr(engine, "block"): engine.block() else: engine.start(blocking=True) def engine_start(engine): if hasattr(engine, "block"): engine.start() else: engine.start(blocking=False) On Jun 4, 4:16 pm, illume <ren...@...> wrote: > cool. > > here's a work around for the api change... if you want it to work with > different versions of cherrypy. > > def engine_block(engine): > if hasattr(engine.block): > engine.block() > else: > engine.start(blocking=True) > > def engine_start(engine): > if hasattr(engine.block): > engine.start() > else: > engine.start(blocking=False) > > cheers, > > On Jun 4, 9:46 am, "Robert Brewer" <fuman...@...> wrote: > > > illume wrote: > > > cherrypy.engine.start(blocking=False) is how you get it to not block > > > in 3.0. > > > > It looks like the API is broken for cherrypy.engine.start(blocking = > > > False) in 3.1 > > > Not broken, just different. In 3.1 you make two calls: engine.start(), > > then engine.block(). That change was made in part to make what you're > > doing more explicit, not to mention more obvious that the feature is > > both there and desirable. > > > Robert Brewer > > fuman...@... You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free Forum Powered by Nabble | Forum Help |