Re: Catching exceptions of cherrypy.engine.start?
"Joseph S. Tate" <[email protected]> Thu, 10 Nov 2016 18:22:41 +0000
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <CA+WDQbGTRvmdYcHEMXp-FJymABZDuehpRz4=-PFmy9mFup-EUg@mail.gmail.com> |
I think you may need to modify cherrypy for that. There may be a way to modify the behavior in an engine plugin, but I doubt it. We do something internally here to configure on arbitrary ports, but I didn't write that code, so I can't tell you off the top of my head how to do it. I guess I'd suggest that rather than having the engine fail, you pre-test the port before calling start(). This post shows how to pre-bind the port before calling start. It refers to the WSGI server, but the standard server works the same way. http://stackoverflow.com/questions/20533480/can-i-get-cherrypy-to-find-its-own-available-port On Thu, Nov 10, 2016 at 3:00 AM Andrew Maizels <[email protected]> wrote: > Three options I can think of: > > > 1. Use an application server like uWSGI or Green Unicorn to keep your > CherryPy app running. > > 2. Use multiprocessing and spin off a separate process for CherryPy. > Join that process and restart it if it exits. But at some point you're > better off going with an application server which will do this for you. > > 3. Write a little startup script that will restart the program if it > dies. That works well as long as it exits cleanly and doesn't hang. If > you find you need to check for that you're probably better off with option > 1 again. > > > On Thu, Nov 10, 2016 at 2:12 PM, Shiming He <[email protected]> wrote: > > Hi, > > When the port is occupied upon calling cherrypy.engine.start(), I'm seeing > the following exceptions thrown at the console: > > OSError: Port 8080 not free on '127.0.0.1' > cherrypy.process.wspbus.ChannelFailures: OSError("Port 8080 not free on > '127.0.0.1'",) > > Eventually, cherrypy will shutdown the entire Python process, regardless > of the fact that I have something else running within the same process. > > Usually in such situation, I can try to catch such exception, reconfigure > the port and let cherrypy try again. However, putting try except block > around engine.start() doesn't seem to do the trick. It appears the > exception was caught in another thread. > > My question is, how do I catch such exception, so that my process and keep > trying for port instead of being terminated? > > Best regards, > He Shiming > > -- > You received this message because you are subscribed to the Google Groups > "cherrypy-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > Visit this group at https://groups.google.com/group/cherrypy-users. > For more options, visit https://groups.google.com/d/optout. > > > > > -- > Ahh... We are all heroes; you and Boo and I. > Hamsters and rangers everywhere, rejoice! > Read Peopleware! > http://www.amazon.com/Peopleware-Productive-Projects-Teams-Second/dp/0932633439 > > -- > You received this message because you are subscribed to the Google Groups > "cherrypy-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > Visit this group at https://groups.google.com/group/cherrypy-users. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/cherrypy-users. For more options, visit https://groups.google.com/d/optout.