Skip to content
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

Use context for runtime, and allow to control timeout for script running? #470

Open
Solveay opened this issue Jun 4, 2023 · 1 comment

Comments

@Solveay
Copy link

Solveay commented Jun 4, 2023

No description provided.

@adonovan
Copy link
Collaborator

adonovan commented Jun 4, 2023

You can already achieve this with the current API, but it requires an additional goroutine to transmit cancellation of ctx to the interpreter, something like this:

{
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	go func() {
		<-ctx.Done()
		thread.Cancel("context cancelled")
	}()
	... evaluate starlark in 'thread' ...
}

Perhaps we could make this simpler by adding a convenience function to the API, or maybe all it needs is an executable example of cancellation in action.

If you pass the context in the thread using Thread.SetLocal, then long-running built-in functions can retrieve it and honor cancellation too; see #252 (comment).

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants