{"action":"created","issue":{"url":"https://api.github.com/repos/python-cmd2/cmd2/issues/584","repository_url":"https://api.github.com/repos/python-cmd2/cmd2","labels_url":"https://api.github.com/repos/python-cmd2/cmd2/issues/584/labels{/name}","comments_url":"https://api.github.com/repos/python-cmd2/cmd2/issues/584/comments","events_url":"https://api.github.com/repos/python-cmd2/cmd2/issues/584/events","html_url":"https://github.com/python-cmd2/cmd2/issues/584","id":371975360,"node_id":"MDU6SXNzdWUzNzE5NzUzNjA=","number":584,"title":"A 'signal only works in main thread' Error during startup","user":{"login":"bhairav13","id":5846631,"node_id":"MDQ6VXNlcjU4NDY2MzE=","avatar_url":"https://avatars2.githubusercontent.com/u/5846631?v=4","gravatar_id":"","url":"https://api.github.com/users/bhairav13","html_url":"https://github.com/bhairav13","followers_url":"https://api.github.com/users/bhairav13/followers","following_url":"https://api.github.com/users/bhairav13/following{/other_user}","gists_url":"https://api.github.com/users/bhairav13/gists{/gist_id}","starred_url":"https://api.github.com/users/bhairav13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhairav13/subscriptions","organizations_url":"https://api.github.com/users/bhairav13/orgs","repos_url":"https://api.github.com/users/bhairav13/repos","events_url":"https://api.github.com/users/bhairav13/events{/privacy}","received_events_url":"https://api.github.com/users/bhairav13/received_events","type":"User","site_admin":false},"labels":[{"id":554473465,"node_id":"MDU6TGFiZWw1NTQ0NzM0NjU=","url":"https://api.github.com/repos/python-cmd2/cmd2/labels/documentation","name":"documentation","color":"5319e7","default":false},{"id":324131052,"node_id":"MDU6TGFiZWwzMjQxMzEwNTI=","url":"https://api.github.com/repos/python-cmd2/cmd2/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":324131055,"node_id":"MDU6TGFiZWwzMjQxMzEwNTU=","url":"https://api.github.com/repos/python-cmd2/cmd2/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":{"login":"tleonhardt","id":2812720,"node_id":"MDQ6VXNlcjI4MTI3MjA=","avatar_url":"https://avatars1.githubusercontent.com/u/2812720?v=4","gravatar_id":"","url":"https://api.github.com/users/tleonhardt","html_url":"https://github.com/tleonhardt","followers_url":"https://api.github.com/users/tleonhardt/followers","following_url":"https://api.github.com/users/tleonhardt/following{/other_user}","gists_url":"https://api.github.com/users/tleonhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/tleonhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tleonhardt/subscriptions","organizations_url":"https://api.github.com/users/tleonhardt/orgs","repos_url":"https://api.github.com/users/tleonhardt/repos","events_url":"https://api.github.com/users/tleonhardt/events{/privacy}","received_events_url":"https://api.github.com/users/tleonhardt/received_events","type":"User","site_admin":false},"assignees":[{"login":"tleonhardt","id":2812720,"node_id":"MDQ6VXNlcjI4MTI3MjA=","avatar_url":"https://avatars1.githubusercontent.com/u/2812720?v=4","gravatar_id":"","url":"https://api.github.com/users/tleonhardt","html_url":"https://github.com/tleonhardt","followers_url":"https://api.github.com/users/tleonhardt/followers","following_url":"https://api.github.com/users/tleonhardt/following{/other_user}","gists_url":"https://api.github.com/users/tleonhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/tleonhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tleonhardt/subscriptions","organizations_url":"https://api.github.com/users/tleonhardt/orgs","repos_url":"https://api.github.com/users/tleonhardt/repos","events_url":"https://api.github.com/users/tleonhardt/events{/privacy}","received_events_url":"https://api.github.com/users/tleonhardt/received_events","type":"User","site_admin":false}],"milestone":null,"comments":12,"created_at":"2018-10-19T14:12:41Z","updated_at":"2018-10-22T12:25:44Z","closed_at":null,"author_association":"NONE","body":"In my script, I start Cmd2 under a separate thread.  This was fine until Cmd2 added signal catching support in some of the latest versions.  Now, when starting up the script, I get this error:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.6/threading.py\", line 916, in _bootstrap_inner\r\n    self.run()\r\n  File \"/usr/lib/python3.6/threading.py\", line 864, in run\r\n    self._target(*self._args, **self._kwargs)\r\n  File \"<redacted>/lib/python3.6/site-packages/cmd2.py\", line 2875, in cmdloop\r\n    self.preloop()\r\n  File \"<redacted>/lib/python3.6/site-packages/cmd2.py\", line 1516, in preloop\r\n    signal.signal(signal.SIGINT, self.sigint_handler)\r\n  File \"/usr/lib/python3.6/signal.py\", line 47, in signal\r\n    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))\r\nValueError: signal only works in main thread\r\n```\r\n\r\nApart from changing my script (which is a big change), is there anyway to by-pass the signal handling?  I don't really care for the signal handling as I take care of it internally in my script anyway.\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/python-cmd2/cmd2/issues/comments/431819955","html_url":"https://github.com/python-cmd2/cmd2/issues/584#issuecomment-431819955","issue_url":"https://api.github.com/repos/python-cmd2/cmd2/issues/584","id":431819955,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTgxOTk1NQ==","user":{"login":"kmvanbrunt","id":28899027,"node_id":"MDQ6VXNlcjI4ODk5MDI3","avatar_url":"https://avatars1.githubusercontent.com/u/28899027?v=4","gravatar_id":"","url":"https://api.github.com/users/kmvanbrunt","html_url":"https://github.com/kmvanbrunt","followers_url":"https://api.github.com/users/kmvanbrunt/followers","following_url":"https://api.github.com/users/kmvanbrunt/following{/other_user}","gists_url":"https://api.github.com/users/kmvanbrunt/gists{/gist_id}","starred_url":"https://api.github.com/users/kmvanbrunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmvanbrunt/subscriptions","organizations_url":"https://api.github.com/users/kmvanbrunt/orgs","repos_url":"https://api.github.com/users/kmvanbrunt/repos","events_url":"https://api.github.com/users/kmvanbrunt/events{/privacy}","received_events_url":"https://api.github.com/users/kmvanbrunt/received_events","type":"User","site_admin":false},"created_at":"2018-10-22T12:25:44Z","updated_at":"2018-10-22T12:25:44Z","author_association":"CONTRIBUTOR","body":"@bhairav13 Does the long-running task need to reach a minimum point before the CLI is started or would you say the CLI is fairly independent of this start-up task? Also, what happens in your application if the user types **quit**? Does the whole application, including the start-up task, close?\r\n\r\nI'm asking these questions because I'm still not sure why the long-running task can't be its own thread that starts before you call `cmdloop()`. Without seeing the code I'm only guessing and perhaps there are valid reasons for your design. However, user interfaces typically should be the main thread and in the case of **cmd2** you are actually missing out on some features by not having it run in this fashion.\r\n\r\nRegardless, we have implemented the proposed fix to prevent the crashing you were experiencing so you should be good to go once it's merged in."}}
{"actor":{"display_login":"kmvanbrunt"}}