Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

green.socket._wait_{read,write} consumes external gevent.Timeout's #242

Merged
merged 4 commits into from Aug 8, 2012

Conversation

sfriesel
Copy link
Contributor

@sfriesel sfriesel commented Aug 6, 2012

see #241

@minrk
Copy link
Member

minrk commented Aug 6, 2012

If you could add a test, this is definitely the right way to go.

@minrk
Copy link
Member

minrk commented Aug 6, 2012

Such a test would be a simple confirmation that recv with nothing incoming is properly interrupted by a Timeout, and would belong in zmq.tests.test_socket:TestSocketGreen. Let me know if you are comfortable doing that, otherwise I can take it from here.

@sfriesel
Copy link
Contributor Author

sfriesel commented Aug 7, 2012

I added a test and some cleanup when the wait gets interrupted (otherwise the socket gets stuck when interrupted), though I'm not sure if always resetting the AsyncResult breaks something somewhere else. I'm pretty new to unittesting, so any comments or corrections would be much appreciated.

g = gevent.spawn_later(0.2, lambda: a.send(b'hi'))
timeout = gevent.Timeout(0.1)
timeout.start()
with self.assertRaises(gevent.Timeout) as cm:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is not available in Python 2.6, so we need self.assertRaises(gevent.Timeout, b.recv)

Also, lets extend the timeout for g to a more comfortable distance (say, 0.5). We can get false failures when running tests on slow VMs if our times are too short.

@minrk
Copy link
Member

minrk commented Aug 7, 2012

I'm not sure if always resetting the AsyncResult breaks something somewhere else.

This is the right thing to do. The way the code is written, only one greenlet can be waiting on a given event. If the AsyncResult is not set, that means that someone is currently waiting on the event (and concurrent attempts to wait on it should raise). Raising a timeout here means giving up on the wait, so it should be set.

@minrk
Copy link
Member

minrk commented Aug 8, 2012

Perfect, thanks!

minrk added a commit that referenced this pull request Aug 8, 2012
Don't consume Timeouts in `gevent.socket._wait_{read,write}`

other timeouts could be consumed by the timeout used to workaround the gevent bug for missing events.

closes #241
@minrk minrk merged commit 6277a90 into zeromq:master Aug 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants