{"action":"created","issue":{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/1869","repository_url":"https://api.github.com/repos/pyinstaller/pyinstaller","labels_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/1869/labels{/name}","comments_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/1869/comments","events_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/1869/events","html_url":"https://github.com/pyinstaller/pyinstaller/issues/1869","id":139667094,"number":1869,"title":"PyInstaller error with sys.exit()","user":{"login":"goodtiding5","id":179489,"avatar_url":"https://avatars.githubusercontent.com/u/179489?v=3","gravatar_id":"","url":"https://api.github.com/users/goodtiding5","html_url":"https://github.com/goodtiding5","followers_url":"https://api.github.com/users/goodtiding5/followers","following_url":"https://api.github.com/users/goodtiding5/following{/other_user}","gists_url":"https://api.github.com/users/goodtiding5/gists{/gist_id}","starred_url":"https://api.github.com/users/goodtiding5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goodtiding5/subscriptions","organizations_url":"https://api.github.com/users/goodtiding5/orgs","repos_url":"https://api.github.com/users/goodtiding5/repos","events_url":"https://api.github.com/users/goodtiding5/events{/privacy}","received_events_url":"https://api.github.com/users/goodtiding5/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/labels/bootloader","name":"bootloader","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-09T18:52:02Z","updated_at":"2016-03-15T11:08:42Z","closed_at":null,"body":"There seems an issue handling sys.exit() or 'raise SystemExit' for python 2.7.\r\n\r\nHere is how to reproduce the problem:\r\n\r\nSuppose we have a script 'foobar.py':\r\n\r\n```\r\n#!/usr/bin/env` python\r\n\r\nimport sys\r\nimport os\r\n\r\nif __name__ == '__main__':\r\n    print >>sys.stderr, \"This is a test, please ignore!\"\r\n    sys.exit(0)\r\n```\r\n\r\nNow let's run pyinstaller as `pyinstaller -F -n foobar foobar.py`.  \r\n\r\nRun `dist/foobar`, we have the following output:\r\n\r\n```\r\n$ dist/foobar\r\nThis is a test, please ignore!\r\nFailed to execute script foobar\r\n```\r\nHowever, if we run `python foobar.py`, it produces:\r\n\r\n```\r\n$ python foobar.py\r\nThis is a test, please ignore!\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/comments/196767649","html_url":"https://github.com/pyinstaller/pyinstaller/issues/1869#issuecomment-196767649","issue_url":"https://api.github.com/repos/pyinstaller/pyinstaller/issues/1869","id":196767649,"user":{"login":"htgoebel","id":784161,"avatar_url":"https://avatars.githubusercontent.com/u/784161?v=3","gravatar_id":"","url":"https://api.github.com/users/htgoebel","html_url":"https://github.com/htgoebel","followers_url":"https://api.github.com/users/htgoebel/followers","following_url":"https://api.github.com/users/htgoebel/following{/other_user}","gists_url":"https://api.github.com/users/htgoebel/gists{/gist_id}","starred_url":"https://api.github.com/users/htgoebel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htgoebel/subscriptions","organizations_url":"https://api.github.com/users/htgoebel/orgs","repos_url":"https://api.github.com/users/htgoebel/repos","events_url":"https://api.github.com/users/htgoebel/events{/privacy}","received_events_url":"https://api.github.com/users/htgoebel/received_events","type":"User","site_admin":false},"created_at":"2016-03-15T11:08:42Z","updated_at":"2016-03-15T11:08:42Z","body":"@codewarrior0 What about registering an at-exit function. [Py_Exit](https://docs.python.org/2/c-api/sys.html#c.Py_Exit) calls `Py_Finalize`, which runs the At-Exit function. Maybe this could even solve signal handling #208."}}