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

(enh) add OS / Process.exit #74

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

joshgoebel
Copy link
Contributor

@joshgoebel joshgoebel commented Apr 26, 2021

Changes:

  • allows immediately terminating the running script and setting the result code

This is needed for usage with terminal scripting, CI (test suites), build systems, etc. Being able to return an error code (without purposely crashing) is necessary for many different uses cases.


I think this is sufficient because freeVm() does all the
cleanup calling ioShutdown and schedulerShutdown(). What
I'm not 100% sure of is if I need to address this:

Then, after uv_run returns you can use uv_walk to close
all handles and run the loop one last time so that
close callbacks are called.

If so I think I can add it fairly easily. I've fully implemented closing all handles now.

Ref: libuv/libuv#709

@joshgoebel joshgoebel mentioned this pull request Apr 29, 2021
54 tasks
@joshgoebel joshgoebel force-pushed the process_exit branch 2 times, most recently from 6e3168d to 830129d Compare May 10, 2021 05:05
@joshgoebel
Copy link
Contributor Author

Updated: Attempts to properly clean up fully before stopping completely. This also improves scheduler error handling which also uses uv_stop to hard stop which may not fully clean-up...

@joshgoebel joshgoebel changed the title (enh) add Process.exit (enh) add OS / Process.exit May 10, 2021
@joshgoebel
Copy link
Contributor Author

Converting to draft, seems obvious now this needs more work.

@joshgoebel
Copy link
Contributor Author

joshgoebel commented May 28, 2021

Fairly confident this works:

joshgoebel@1de80e5

The flow:

  • Wren VM calls into C for Process.exit_
  • uv_stop() - stop the UV event loop
  • Control returns to Wren VM
  • Fiber.suspend - to stop the VM also
  • VM is halted and CLI terminates because there is no more work to do

I can update my patch here if there is agreement this is a viable solution.

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

Successfully merging this pull request may close these issues.

1 participant