brgl / libgpiod

This is a mirror of the original repository over at kernel.org. This github page is for discussions and issue reporting only. PRs can be discussed here but the patches need to go through the linux-gpio mailing list.
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
Other
307 stars 106 forks source link

Calling line.event_wait in thread hangs main program #26

Closed sgjava closed 6 years ago

sgjava commented 6 years ago

Code I have using CFFI/Python 3 and libgpiod 1.0 line.event_wait worked fine in a thread. Using your new Python bindings this code hangs main program until timeout or event fires.

brgl commented 6 years ago

That's interesting, I'm curious if it's not something related to the Global Interpreter Lock in python. I'll take a look.

brgl commented 6 years ago

Seems like I will need to use Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS before and after the internal call to gpiod_line_event_wait() respectively.

sgjava commented 6 years ago

Let me know when you commit changes and I'll test, thanks.

brgl commented 6 years ago

@sgjava I don't really have time to test it today, but I pushed a fix to topic/python-locking branch that should theoretically fix it. I should probably add these macros around all blocking operations in the module. Let me know if you can test it and if it works.

sgjava commented 6 years ago

I just tested event_wait and it works as expected in a thread. Let me know when you commit changes to master. I'll finish up converting the rest of my example code to the new bindings.

brgl commented 6 years ago

Done.

sgjava commented 6 years ago

I just built and tested my threading example. Looks good, thanks.