Re: Catching exceptions of cherrypy.engine.start?
Andrew Maizels <[email protected]> Thu, 10 Nov 2016 19:00:32 +1100
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <CACETAqjZpvxTyQ9JPGaX1zuLYi57qHCDZggZNwPh+PPEMLV0Mg@mail.gmail.com> |
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.