Hi Shaun,
Thanks for taking time to report this issue. I've also bumped into it
but haven't had time to look closely. I've got some comments though.
> The root of the issue is that libev (libevent as well) caches the time
I've made a simple test (attached) to reproduce this issue and it
shows that gevent-0.13/libevent does not actually have this problem.
Are you sure about libevent having this problem as well?
> One possible solution is to litter time.sleep(0)'s throughout the code to
> force a yield and, thus, a fresh run through libev's dispatch loop with a
> refreshed cache time. This seems really bad
This is unnecessary. Libev has a special function to update cached
time: ev_now_update:
http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#The_special_problem_of_time_updates
It is exposed by gevent as gevent.get_hub().loop.update()
So you can use it instead of sleep(0).
One idea on how to use it is to set up an alarm handler to
periodically call loop.update()
loop = gevent.get_hub().loop
signal.signal(signal.SIGALRM, lambda *args: loop.update())
signal.setitimer(signal.ITIMER_REAL, 0.1, 0.1)
This will update cached time every 100ms. Which means the problem is
reduced from "timeouts expire earlier" to "timeouts expire earlier but
not earlier than by 100ms".
You can of course tune the parameter to suit your application. The
socket connect timeouts are likely to be bigger than 100ms so it
should fix the problem.
I would also prefer libev to defer timer starts to the end of the
event dispatch cycle. I wonder if the current behaviour is accidental
or is it intentional and have some desired properties. You mentioned
that you plan to ask libev developer about this - have you done so?
Regards,
Denis.
Thanks for taking time to report this issue. I've also bumped into it
but haven't had time to look closely. I've got some comments though.
I've made a simple test (attached) to reproduce this issue and it
> The root of the issue is that libev (libevent as well) caches the time
shows that gevent-0.13/libevent does not actually have this problem.
Are you sure about libevent having this problem as well?
> One possible solution is to litter time.sleep(0)'s throughout the code toThis is unnecessary. Libev has a special function to update cached
> force a yield and, thus, a fresh run through libev's dispatch loop with a
> refreshed cache time. This seems really bad
time: ev_now_update:
http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#The_special_problem_of_time_updates
It is exposed by gevent as gevent.get_hub().loop.update()
So you can use it instead of sleep(0).
One idea on how to use it is to set up an alarm handler to
periodically call loop.update()
loop = gevent.get_hub().loop
signal.signal(signal.SIGALRM, lambda *args: loop.update())
signal.setitimer(signal.ITIMER_REAL, 0.1, 0.1)
This will update cached time every 100ms. Which means the problem is
reduced from "timeouts expire earlier" to "timeouts expire earlier but
not earlier than by 100ms".
You can of course tune the parameter to suit your application. The
socket connect timeouts are likely to be bigger than 100ms so it
should fix the problem.
I would also prefer libev to defer timer starts to the end of the
event dispatch cycle. I wonder if the current behaviour is accidental
or is it intentional and have some desired properties. You mentioned
that you plan to ask libev developer about this - have you done so?
If the signal is set up with signal module, then yes, it does.
On Sat, Oct 8, 2011 at 5:30 AM, Shaun Lindsay <srli...@gmail.com> wrote:
> Just looked a bit closer and noticed that you were using an actual signal,
> not the monkey-patched gevent signal, thus avoiding my concerns about
> signalfd/fd callbacks in general. You'd need to set this up before
> monkey-patching then.
No, you don't, because signal module is not monkey patched.
See also my comment here: http://code.google.com/p/gevent/issues/detail?id=97#c7
No, I don't have any plans for 0.13.x. I have not used it myself for a
long time and rather spend time on 1.0 which is what I use. Why don't
you try 1.0beta?
No, I don't have any plans for 0.13.x. I have not used it myself for a
long time and rather spend time on 1.0 which is what I use. Why don't
you try 1.0beta?
On Fri, May 11, 2012 at 8:33 PM, Vitaly <> wrote:Why? Google groups web interface does not show it without asking for a captcha.
> Denis -- could you please delete your post that has my email address in the
> quote. It must have snuck in there from your email reply.
On Fri, May 11, 2012 at 12:54 PM, Vitaly <> wrote:
> Are there any plans for a fix along the lines of your recent libev fix?
No, I don't have any plans for 0.13.x. I have not used it myself for a
long time and rather spend time on 1.0 which is what I use. Why don't
you try 1.0beta?
Is this bug come from libevent or gevent?
If I could get ride of it without yet switching to gevent >= 1.0 i
would love it. (you know, migration, maintenance, time to do it...)
François-Xavier Bourlet