-
Notifications
You must be signed in to change notification settings - Fork 27
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
Macro to timeout operations that take too long #282
Comments
Not sure what you are doing in Clapeyron. (Typically for an MWE (MINIMAL workable example) you don't need to install a foreign dependency.) @app MyApp begin
@in a = 12
end
function f(model)
println("before $(model.a[])")
sleep(1)
println("after $(model.a[])")
end then julia> model = @init MyApp;
julia> @timeout 2 f(model)
before 12
after 12
julia> @timeout 0.2 f(model)
before 12
"Timed out" |
My apologies for not being clearer. I can get it to work for simple examples like the one you've shown. However, once calls to module functions are used, like f(x) = exp(-x^2)-sin(x)
@time fzeros(f,-10000,10000);
# 0.074126 seconds (1.39 M allocations: 38.786 MiB, 3.51% gc time)
@timeout 1e-4 fzeros(f,-10000,10000) # Doesn't timeout Any idea why that would be? |
I could reproduce that and still don't know why. Interestingly, it works if you keep the wrapping julia> @timeout 0.02 @time(fzeros(f,-10000,10000))
0.074842 seconds (1.38 M allocations: 38.043 MiB, 5.59% gc time)
"Timed out" |
Really weird... Although in the above, it still computed the function and then timed-out. So it didn't do its job... |
Hi!
On my Genie app, there are some cases where, if the user inputs unphysical conditions, the solvers will get stuck / take a long time to output an unreasonable result. As such, it would be great to have some sort of macro that will only allow a task to only run for a certain amount of time. There was an example here: https://discourse.julialang.org/t/simple-timeout-of-function/99578/3
The macro they propose looks like this:
However, I've found that this macro doesn't work for my cases. Here is an MWE (you'll need to install Clapeyron):
The text was updated successfully, but these errors were encountered: