-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Corrections to timedwait
methods
#35103
Conversation
Bump |
I'll add some tests today |
d372b20
to
70d15d4
Compare
Alright, tests have now been added. One thing to note is that Also note I've removed the |
|
||
function Base.timedwait(testcb::Function, timeout::Period; pollint::Period=Millisecond(100)) | ||
timedwait(testcb, toms(timeout) / 1000, pollint=toms(pollint) / 1000) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll call out that toms
truncates to milliseconds which means we're losing precision if a user passes in say Nanosecond(1)
for either the timeout
or pollint
. However, since timedwait
can only actually support millseconds this isn't really an issue.
This is one of those cases where two wrongs can make a right ;)
base/asyncevent.jl
Outdated
@@ -284,7 +285,8 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1) | |||
|
|||
if !testcb() | |||
t = Timer(timercb, pollint, interval = pollint) | |||
ret = fetch(done)::Symbol | |||
ret = fetch(done) | |||
ret isa Exception && rethrow(ret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should rely on the type of e
; can use a boolean flag instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about if we store a Tuple{Symbol, Union{Nothing, Exception}}
in the channel? Then this code would look like:
ret, e = fetch(done)
ret === :error && rethrow(e)
70d15d4
to
34eb22b
Compare
Looks like I need to increase my timing tolerance:
|
Tolerance is still too small:
|
I'm either really lucky or really unlucky:
I'll go to a tolerance of 0.4 |
base/asyncevent.jl
Outdated
@@ -284,7 +285,8 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1) | |||
|
|||
if !testcb() | |||
t = Timer(timercb, pollint, interval = pollint) | |||
ret = fetch(done)::Symbol | |||
ret, e = fetch(done) | |||
ret === :error && rethrow(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rethrow
doesn't work outside a catch block (it's throwing ERROR: rethrow(exc) not allowed outside a catch block
) so you have to use throw
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad mistake on my part. Unfortunately this means that the exception thrown won't have the original stacktrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if the callback raises an exception on the first call will generate the original stack trace. Exceptions raised after will not have the original stack trace. This seems better than silencing all exceptions from the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively I can have timedwait
return :error
again and just capture exceptions from the first testcb
call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could capture the stack trace and store it in a CapturedException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the code to always return a CapturedException
CI failures look network related |
Made argument names consistent with documentation where reasonable.
39d4cd9
to
906f6d2
Compare
Rebased changes |
* Refactor methods of sleep, Timer, and timedwait Made argument names consistent with documentation where reasonable. * Support pollint keyword in timedwait using Periods * Allow timedwait to take Real * Add tests for timedwait * Fix bug with sub-millisecond pollint * Test timedwait with Period parameters * Rethrow exceptions raised by timedwait callback
* Refactor methods of sleep, Timer, and timedwait Made argument names consistent with documentation where reasonable. * Support pollint keyword in timedwait using Periods * Allow timedwait to take Real * Add tests for timedwait * Fix bug with sub-millisecond pollint * Test timedwait with Period parameters * Rethrow exceptions raised by timedwait callback
Mainly I wanted to update the
timedwait
function to be able to takeReal
instead of justFloat64
. During this process I found that thetimedwait
method which takesPeriod
was missing thepollint
keyword and I made some adjustments there as well.The
timedwait
function currently doesn't have any tests so I'll probably also do that as part of this PR.