tonysimpson / nanomsg-python

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
MIT License
382 stars 85 forks source link

nonblocking ? #37

Closed stuaxo closed 8 years ago

stuaxo commented 9 years ago

Hi, Does this support nonblocking mode ? I'm thinking of using PAIR with it ..

S

vac commented 9 years ago

I don't have much experience in using this library but making non-blocking BUS was not a problem! I think that in PAIR it would be the same:

    data = your_socket.recv(flags=nanomsg.DONTWAIT)

The only problem is that it raises exception instead of return None - so my code looks like this:

    try:
        data = your_socket.recv(flags=nanomsg.DONTWAIT)
    except nanomsg.NanoMsgAPIError:
        data=None

If you want to detect proper exceptions that you have to check error codes (errno) of exception.

stuaxo commented 9 years ago

Cheers :)