Lawouach / WebSocket-for-Python

WebSocket client and server library for Python 2 and 3 as well as PyPy (ws4py 0.5.1)
https://ws4py.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
1.12k stars 288 forks source link

retry polling if system got interrupted #151

Closed rp- closed 7 years ago

rp- commented 10 years ago

might happen if run through gdb or system hibernation

I'm not 100% sure if this fix is really 100 good, as I don't know which real interruptions could happen where ws4py wants to stop. But if you have cython compiled code with ws4py you can't use it with gdb anymore. see as a few references: http://stackoverflow.com/questions/2252981/gdb-error-unable-to-execute-epoll-wait-4-interrupted-system-call https://github.com/mopidy/mopidy/issues/718

Lawouach commented 10 years ago

Hi, thanks a lot for the information. I wasn't aware of this.

Regarding the fix, what worries me a little is that try/catch blocks aren't cheap in a loop, I would rather make it more local or even get it outside the while block.

rp- commented 10 years ago

Yeah this just looked like a good spot, since there happens another polling within this loop. Didn't think about any performance implications.

EternityForest commented 9 years ago

According to this http://stackoverflow.com/questions/2522005/cost-of-exception-handlers-in-python, try/except might actually be faster than an if: if I am reading it right.

I just made a similar pull request before I saw this one that catches IOError. I don't think InterruptedError and IOError are related, and I was getting IOErrors IIRC. Is InterruptedError a subclass? Are there two different errors that the resume from suspend could be sending?

Here: http://sebastianraschka.com/Articles/python3_OSError.html it looks like InterruptedError derives from OSError(as does IOError) making them siblings.

tito commented 7 years ago

This has been implemented by another pr directly in poller implementation. So the issue will not raise anymore (if select() returned something, i doubt read() will fail, but let's see.)