{"action":"created","issue":{"url":"https://api.github.com/repos/thesharp/daemonize/issues/43","repository_url":"https://api.github.com/repos/thesharp/daemonize","labels_url":"https://api.github.com/repos/thesharp/daemonize/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/thesharp/daemonize/issues/43/comments","events_url":"https://api.github.com/repos/thesharp/daemonize/issues/43/events","html_url":"https://github.com/thesharp/daemonize/issues/43","id":131873868,"number":43,"title":"Error on exit","user":{"login":"citosid","id":201430,"avatar_url":"https://avatars.githubusercontent.com/u/201430?v=3","gravatar_id":"","url":"https://api.github.com/users/citosid","html_url":"https://github.com/citosid","followers_url":"https://api.github.com/users/citosid/followers","following_url":"https://api.github.com/users/citosid/following{/other_user}","gists_url":"https://api.github.com/users/citosid/gists{/gist_id}","starred_url":"https://api.github.com/users/citosid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citosid/subscriptions","organizations_url":"https://api.github.com/users/citosid/orgs","repos_url":"https://api.github.com/users/citosid/repos","events_url":"https://api.github.com/users/citosid/events{/privacy}","received_events_url":"https://api.github.com/users/citosid/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-06T16:37:35Z","updated_at":"2016-02-23T16:38:49Z","closed_at":null,"body":"I have this code:\r\n\r\n```python\r\ndaemon = Daemonize(\r\n    app=\"Encoder\",\r\n    pid=pid_file,\r\n    action=self.__daemonize,\r\n    foreground=False if self.env == 'production' else True,\r\n    logger=logging\r\n)\r\ndaemon.start()\r\n```\r\n\r\nAnd in the exit handler for the process (when someone either hits ctrl-c or run the stop process):\r\n\r\n```python\r\nwith open(pid_file, 'r') as content_file:\r\n    pid = content_file.read()\r\nos.kill(int(pid), signal.SIGTERM)\r\n```\r\n\r\nThat works ok, but when it exists (although it executes everything ok) I see this error:\r\n\r\n```\r\nError in atexit._run_exitfuncs:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.4/dist-packages/daemonize.py\", line 71, in exit\r\n    os.remove(self.pid)\r\nFileNotFoundError: [Errno 2] No such file or directory: '/var/run/encoder.pid'\r\n```\r\n\r\nReading the code, I see this:\r\n\r\n```python\r\n        signal.signal(signal.SIGTERM, self.sigterm)\r\n        atexit.register(self.exit)\r\n```\r\n\r\nAnd that has this:\r\n\r\n```python\r\n    def sigterm(self, signum, frame):\r\n        \"\"\"\r\n        These actions will be done after SIGTERM.\r\n        \"\"\"\r\n        self.logger.warn(\"Caught signal %s. Stopping daemon.\" % signum)\r\n        os.remove(self.pid)\r\n        sys.exit(0)\r\n\r\n    def exit(self):\r\n        \"\"\"\r\n        Cleanup pid file at exit.\r\n        \"\"\"\r\n        self.logger.warn(\"Stopping daemon.\")\r\n        os.remove(self.pid)\r\n        sys.exit(0)\r\n```\r\n\r\nIf I understand the code correctly, that will try to delete the pid file twice, is that right? Am I doing something wrong?"},"comment":{"url":"https://api.github.com/repos/thesharp/daemonize/issues/comments/187780991","html_url":"https://github.com/thesharp/daemonize/issues/43#issuecomment-187780991","issue_url":"https://api.github.com/repos/thesharp/daemonize/issues/43","id":187780991,"user":{"login":"citosid","id":201430,"avatar_url":"https://avatars.githubusercontent.com/u/201430?v=3","gravatar_id":"","url":"https://api.github.com/users/citosid","html_url":"https://github.com/citosid","followers_url":"https://api.github.com/users/citosid/followers","following_url":"https://api.github.com/users/citosid/following{/other_user}","gists_url":"https://api.github.com/users/citosid/gists{/gist_id}","starred_url":"https://api.github.com/users/citosid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citosid/subscriptions","organizations_url":"https://api.github.com/users/citosid/orgs","repos_url":"https://api.github.com/users/citosid/repos","events_url":"https://api.github.com/users/citosid/events{/privacy}","received_events_url":"https://api.github.com/users/citosid/received_events","type":"User","site_admin":false},"created_at":"2016-02-23T16:38:49Z","updated_at":"2016-02-23T16:38:49Z","body":"The PID is created, and it is deleted. I debug the app, and it is deleted at `sigterm` method. Then, the `self.exit` method is executed and that tries to delete again the file that was deleted by the `self.sigterm` method."}}