thesharp / daemonize

daemonize is a library for writing system daemons in Python.
MIT License
445 stars 64 forks source link

Daemonize.start() shouldn't exit on failures prior to fork. #38

Open rthille opened 8 years ago

rthille commented 8 years ago

When a script tries to daemonize to perform a long running action, it should have the chance to handle errors via exceptions prior to the forking of the child. Currently if there is already a daemon running so the parent can't get a lock on the pid file Daemonize.start() just exits. As an option at least it should just raise an exception which can be more gracefully handled in the main script.

thesharp commented 8 years ago

Hi @rthille

We've decided that we will raise exceptions on every error, instead of exiting silently (or sometimes printing something to the logger). This will be implemented in the nearest future. This issues will be updated with the progress.

As for now, to mitigate your issue, you can try to catch SystemExit.

rthille commented 8 years ago

I'm working on a pull-request for this. Hope to have it working with tests today...

RealOrangeOne commented 5 years ago

I realise this is almost 3 years ago, but did this ever happen? It looks like the current version still terminates the application when something goes wrong, or once the parent has spawned the child, which feels very much incorrect! It also makes the library impossible to write unit tests for, as it keeps terminating mid-way through the tests.

rthille commented 5 years ago

I had working changes, but they were done at a previous company and I never sought authorization to release the change since @thesharp said the project had a different approach for a fix.