trainman419 / python-cec

Other
170 stars 42 forks source link

race condition in command_cb #6

Closed ags799 closed 10 years ago

ags799 commented 10 years ago

I've added some code to command_cb() so that my Python program may receive raw CEC messages. I've added a call to a Python method in between the PyGILState_Ensure() and PyGILState_Release() statements .

The method typically doesn't produce any noticeable action, unless that action is very quick. For example, I can print a hard-coded string like 'CEC message received', but I can't print str(some_object). This behavior occurs even when I run the program under gdb.

I think this qualifies as a race condition. I don't see how, I thought that the PyGILState_Ensure() would take care of this.

Any ideas? Thanks in advance.

trainman419 commented 10 years ago

The locking here is a bit tricky. I'm not sure I have all of it figured out yet either.

The thing I've found is that some of the libcec functions that are called from the main thread appear to call indirectly into the callbacks, and that it's essential that I release the GIL before calling any of the libcec functions. I think I fixed the majority of these in 5c0d0fdbf9108a3414b7e7531f9bc1afe9684009 , but there may still be a few hanging around to get caught up on.

ags799 commented 10 years ago

I don't think there's a race condition. I was calling a method on a Python object that was properly instantiated.