-
Notifications
You must be signed in to change notification settings - Fork 181
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
Fix #113 and add Inf timeout option #116
Conversation
tm = Float64($(esc(t))) | ||
start = time() | ||
tsk = @async $(esc(expr)) | ||
yield() |
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.
Why the yield
here?
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.
Per comment in #113, my concern is that istaskdone
will return false
and cause a 10ms sleep, even if expr
would have executed in a very short time. The yield()
gives the expr
task a chance to run before checking istaskdone
.
e.g.
function f()
t = @async sum([1,2,3])
!istaskdone(t) && sleep(0.01)
end
julia> f()
julia> @time f()
0.013942 seconds (12 allocations: 1.031 KiB)
vs
function f()
t = @async sum([1,2,3])
yield()
!istaskdone(t) && sleep(0.01)
end
julia> f()
julia> @time f()
0.000011 seconds (8 allocations: 880 bytes)
sleep($pollint) | ||
end | ||
istaskdone(tsk) || $(esc(then)) | ||
wait(tsk) |
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.
Can you remind me why the change to wait
here?
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.
Because wait
rethrows the task exception if needed, whereas the current code ends up at no method matching length(::Base.UVError)
From #113 ...
The timeout
macro executes expr
in a new task, waits for a timeout or istaskdone
, then returns task.result
. In the case where expr
throws and exception, the exception is returned as a value when it should be re-thrown.
The result is:
ERROR: MethodError: no method matching length(::Base.UVError)
[1] processresponse!(::HTTP.Client, ::HTTP.Connection{MbedTLS.SSLContext}, ::HTTP.Response, ::String, ::HTTP.Method, ::Task, ::Bool, ::Float64, ::Bool, ::Bool)
at /Users/sam/.julia/v0.6/HTTP/src/client.jl:287
Thanks! |
No description provided.