Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved issue of pywinusb Input threads not closing or terminating. #54

Open
warrenarea opened this issue Feb 7, 2019 · 1 comment
Open

Comments

@warrenarea
Copy link

warrenarea commented Feb 7, 2019

I have had issues in the past of threads not closing
properly. When you set up a raw data handler, pywinusb
creates two threads:

InputReportProcessing
InputReportReader

and in theory, if you script everything correctly, and all your functions
get returned, and you do the proper cleanup, that these threads will (should)
close on their own.

However, i have had instances where this did not take place. I have seen
on stackoverflow there are many people who try to terminate/abort threads,
and because of the locks, it just doesn't seem to be effective.

threading._after_fork()

I discovered this function, that... doesn't seem to be documented, but... the nearest
i can tell, it calls an additional function that is designed to "reset all locks" for python.
This function seems to work wonderfully, and is a good way of freeing up our threads.

I'm not sure if it is something that could be incorporated into the project, because...
you would hate to close all threads or locks that should be in place.... but, maybe it
could still be incorporated... or at very least documented as a last resort option.

Here is code also, to list the threads (for troubleshooting).

for t in threading.enumerate():
    print(t.getName())
@rene-aguirre
Copy link
Owner

Thanks @warrenarea, do you have more details of what version of os, python and pyWinUsb you had when hitting the threading issues?

@c1728p9 invested a lot of time tuning the threading, specially on scenarios involving removing devices. So any hints about reproducing the failures would be appreciated.

I wouldn't discard using a known workaround for sure, can you point us to such discussion threads?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants