twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

stop running block and stop runtimes not work, #281

Closed zhaihao closed 3 months ago

zhaihao commented 1 year ago

Thank you for creating such an awesome plugin.but I ran into some issues.

os:macOS language:python

https://github.com/twibiral/obsidian-execute-code/assets/4202032/1256363b-3e2e-4a2c-93bd-648ed8c13af1

jancbeck commented 1 year ago

Same issue here but with JavaScript. I'm also on MacOS. Node is installed via homebrew. Might be a Mac permissions issue. Perhaps related issue: https://github.com/twibiral/obsidian-execute-code/issues/188

mayurankv commented 10 months ago

I think being able to set the path to pkill would resolve this.

jamesbtan commented 3 months ago

This is old, but I think the issue is that pkill -P also returns 1 if there are no children processes to kill. Then since it is a non-zero exit code, it throws an error even though it should be able to proceed smoothly.

Maybe we can ignore the 1 error code for pkill?

Edit: Wrapping the pkill -P call in a try catch that ignores the error stops the crash, and the process is ended.

However, I am not sure how robust this is and if I am potentially ignoring any true errors.

jancbeck commented 3 months ago

Just wanted to confirm that the issue is still here. When I click the spinner nothing happens. When I click the trashcan in the runtimes pane, console prints :

node:internal/errors:867 Uncaught (in promise) Error: Command failed: pkill -P 50125 at __node_internal_genericNodeError (node:internal/errors:867:15) at checkExecSyncError (node:child_process:911:11) at execSync (node:child_process:983:15) at node:electron/js2c/asar_bundle:2:12758 at killWithChildren_default (plugin:execute-code:12309:39) at eval (plugin:execute-code:12377:7) at new Promise () at NodeJSExecutor.stop (plugin:execute-code:12373:12) at HTMLButtonElement.eval (plugin:execute-code:12940:53)

jamesbtan commented 3 months ago

Yes. When you close the runtime, the plugin also tries to close any child processes that the runtime may have spawned.

However, if your runtime has no child process, then the pkill will return an error code of 1 to signify that no processes were found. The execSync helper function throws an error on all non-zero error codes though, so it logs the error and stops before it kills the runtime itself.

I have made a pull request with a fix that works for me, you can try to make the change yourself and see if it resolves the issue for you.

twibiral commented 3 months ago

Fixed with new release version 1.12.0