openyou/emokit — pull request #72 by nh2 (2013-03-26 02:06:28+00:00)
Title: Blocking device read() call destroys gevent

Hey,

it's cool that you introduced gevent into the Python code, I think that makes many things much easier to write.

However, there is one issue with that: The `hidraw.read(32)` call is blocking and therefore stops all gevent threads.

It also introduced a bug that an *initial* `gevent.sleep(1)`, as was written in the README example code so far, would delay all EEG data by one second even though this sleep was not in the main loop.

This change fixes all of this by doing this call from a separate real thread, simply forwarding all data to the existing `gevent.Queue` via threading `Queues`.

It would be even better to instead do an event driven `read()` (using `select/epoll/kqueue` techniques, so probably even `gevent.select` in our case), but as far as I know that is not cross-platform; the overhead introduced by the poll I have implemented is quite low and can be traded off for latency (the current default value is 1 ms).

**I could not test the this with windows and OS-level decryption**, so it would be great if somebody could have a short look if that still works as expected.