chrippa / ds4drv

A Sony DualShock 4 userspace driver for Linux
MIT License
1.05k stars 213 forks source link

Added SIGINT handling #78

Closed poconbhui closed 8 years ago

poconbhui commented 8 years ago

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.

poconbhui commented 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.

Ape commented 8 years ago

Would it be a good idea to register the signal handler before doing anything else in the main function?

poconbhui commented 8 years ago

Probably. Done.

Ape commented 8 years ago

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".

poconbhui commented 8 years ago

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.

Ape commented 8 years ago

Oh, I didn't notice that the function was there because of the closure. Regardless, I like the class solution.

Ape commented 8 years ago

Thanks!