On 5/30/12 12:49 PM, Robert Kern wrote:
> I'd like to write some Cython code in a separate thread "with nogil" but still
> communicate from Python code on the main thread. Right now, my pure Python
> prototype uses a Lock and a Condition to communicate with the worker thread. My
> worker loop looks like this:
>
> mutex = threading.Lock()
> have_command = threading.Command(mutex)
>
> with mutex:
> while True:
> have_command.wait()
> cmd = get_command()
> perform_command(cmd)
>
> Does anyone have any recommendations for lock implementations to use? Windows
> needs to work, and it would be ideal if it were cross-platform. Obviously, I
> can't use threading.Lock because it is a Python object, and I don't want to grab
> the GIL just to interact with that.
Never mind. I should have Googled more. It looks like cpython.pythread provides
what I need.
https://github.com/cython/cython/blob/master/Cython/Includes/cpython/pythread.pxd