Catching exceptions of cherrypy.engine.start?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Catching exceptions of cherrypy.engine.start?

Shiming He
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Catching exceptions of cherrypy.engine.start?

Andrew Maizels
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Catching exceptions of cherrypy.engine.start?

Joseph S. Tate
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.




On Thu, Nov 10, 2016 at 3:00 AM Andrew Maizels <[hidden email]> 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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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 [hidden email].
To post to this group, send email to [hidden email].
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Loading...