basilisp icon indicating copy to clipboard operation
basilisp copied to clipboard

Allow Interupting Evaluation

Open johannesCmayer opened this issue 6 months ago • 2 comments

It would be great if cider-interrupt would work. I tend to all the time run code that takes longer than I want.

An alternative quick hack would be to have the basilisp nrepl-server trap the SIGUSR2 signal, and then raise e.g. KeyboardInterrupt exception. I am not sure if this would be easy to do. I thought of this because that's exactly what seems to happen in a normal python repl (and the basilisp repl too). Then I could simply create a keybind that finds the repl executable, and sends the signal with the kill command.

johannesCmayer avatar May 15 '25 17:05 johannesCmayer

HI @johannesCmayer,

I don't think it's possible to interrupt the built-in nREPL server using interrupts, since it handles only one request at a time. As a result, it won't even see the interrupt sent by CIDER while it's busy processing a request.

However, this might be achievable with the basilisp-nrepl-async fork. In that model, client requests can be executed on the main thread, while new requests are received concurrently on a separate thread. This setup could allow the listener thread to detect an interrupt request and signal the main thread accordingly.

Do you have a specific real world use case in mind? If so, could you describe the steps involved ? That would help me reproduce the scenario and explore a workable solution.

Thanks

ikappaki avatar May 17 '25 13:05 ikappaki

I was doing the thing I wanted to do in basilisp in julia now. But I still think it would improve basilisp to add this (though don't do it just for me). The use case is: You interactively evaluate some code that has some long running computation, e.g. call HiGHS, Z3, cvx, gradient descent optimization loop, a test that checks many cases, some code that has an infinite loop. If you can interrupt the computation you need to think much less hard about how long your code will run. If you get it wrong you need to press a keyboard shortcut instead of restarting your repl.

Feel free to close this issue. I won't engage with it further (because I don't use basilisp currently).

johannesCmayer avatar May 27 '25 12:05 johannesCmayer