-
Notifications
You must be signed in to change notification settings - Fork 204
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
Is there any way to stop a running script with a timeout? #252
Comments
Currently there is no way to stop a function in the middle of Starlark execution, though it is a feature that has been requested before and may be feasible to implement without a major performance penalty. Is the function you wish to interrupt executing a Starlark loop, or is it calling into a built-in function that takes a long time? If the latter, then you can easily make that built-in function honor the cancellation of a context carried within the thread. For example:
|
My use cases are more like a lightweight FaaS. The user defines a function that I can't control and I call it many times. So when it runs too long, I need to stop/kill it. Is there any difficulty that doesn't implement yet? |
Oh, if you can't trust the user's function then you definitely should not run it in the same address space as your code, as it can trivially consume all available memory and there's nothing we can hope to do about that. Let the operating system help you. Fork and exec a subprocess in a cgroup or setrlimit container that bounds the memory, CPU, and running time. |
@alandonovan do you think it would be a large effort to implement rough cpu/memory metering and limits? I understand if this isn't the goal of the project and that it wouldn't have a home in this codebase, but is there something about the implementation that would make this difficult? |
Yes, I think it's essentially infeasible. An implementation in C++ could in principle impose limits on memory usage, but it would be a major usability challenge. Like I said before, let the operating system help you. It has mechanisms to bound both CPU and memory usage of child process. |
Yep, I'm working on something that takes advantage of those mechanisms to limit memory and cpu use with webassembly: https://github.com/embly/embly With starlark it seemed like it might be possible to get away with an implementation that safely runs user code in the same address space, maybe not measuring the exact amount of memory used, but at least imposing some soft limits base on what is being parsed and executed. Understood though, thanks for the response. |
Can this be marked a duplicate of #160 ? |
Fixed. See Thread.SetMaxExecutionSteps and Thread.Cancel. |
…le#298) This change adds two related features: (1) asynchronous cancellation of Starlark threads (Thread.Cancel), and (2) recording and limiting of the number of abstract computation steps. Fixes issue google#252 Fixes issue google#160
…le#298) This change adds two related features: (1) asynchronous cancellation of Starlark threads (Thread.Cancel), and (2) recording and limiting of the number of abstract computation steps. Fixes issue google#252 Fixes issue google#160
In my use case, I receive a
function
from the user. And I passthrough params and execute it. But I need a way to stop the function running with a timeout (e.g. 2000ms).can starlark-go provide a function like CallContext?
The text was updated successfully, but these errors were encountered: