Closed poconbhui closed 8 years ago
I cleaned the extra import sys and returned the SIGINT handler before calling os.exit. Returning the sigint handler is probably completely superfluous though.
Would it be a good idea to register the signal handler before doing anything else in the main function?
Probably. Done.
This should be soon ready for merge. Remove the empty line on line 141 and move handle_sigint
outside of main
function. Also, I am not sure if the comment on line 144 is adding any value.
After that please squash the commits to a single commit. And use imperative present tense and no trailing dot on the commit message. E.g. "Add SIGINT handling".
Taking it out is a little awkward since it's a closure around threads[]. I'll pull it out as a class and see what you think before squashing.
Oh, I didn't notice that the function was there because of the closure. Regardless, I like the class solution.
Thanks!
Usually when exiting ds4drv with ^C I'd get a lot of traceback garbage. This gets rid of that. It also handles closing the controller threads more gracefully, since https://docs.python.org/2/library/threading.html suggests that daemon threads not closed properly might not release resources properly.
The main bit of trickery here is setting a timeout on epoll.poll. I went for 1 second because it's much higher than the expected time to wait for a controller poll, and short enough that a user won't really notice it. Without that, shutdown freezes until the poll naturally times out.