Fork me on GitHub

Welcome 1700th member of this channel!

🙌 6
🎉 5
clojure 5
👍 3
babashka 4

Anyone else experiencing this on osx when trying to CTRL-c?

Exception in thread "SIGINT handler" java.lang.UnsupportedOperationException: Method not implemented: handle
        at babashka.impl.proxy$method_or_bust.invokeStatic(proxy.clj:8)
        at babashka.impl.proxy$proxy_fn$fn__21284.invoke(proxy.clj:78)
        at babashka.impl.proxy.proxy$java.lang.Object$SignalHandler$d8c00ec7.handle(Unknown Source)
        at sun.misc.Signal$InternalMiscHandler.handle(
        at jdk.internal.misc.Signal$
I've been CTRL-z and then killing the process manually as a workaround =)...


Please provide a complete sequence of steps to reproduce this


Give me a moment, trying to produce a minimal example 😃


Ok, this is plugging into a lot of bb's internals, I suppose my question is, there's signal handlers defined for INT and TERM:

(defmacro set-signal-handler!
  [signal f]
    (sun.misc.Signal. ~signal)
    (proxy [sun.misc.SignalHandler] []
      (handle [signal#] (~f signal#)))))

(set-signal-handler! "INT" cleanup)
(set-signal-handler! "TERM" cleanup)
The error is saying there's no SIGINT handler, I tried adding a SIGINT entry, but I'm getting:
(set-signal-handler! "SIGINT" cleanup)
    ^--- Unknown signal: SIGINT
So I'm assuming that INT is supposed to be SIGINT... So I'm trying to work out why registering (set-signal-handler! "INT" cleanup) is not calling this handler? I should be able to debug from there 😃... If this isn't obvious, that's fine, I'll have to dig into the codebase and work out what's going on 😃... (which may be what's required, I'm a bit unfamilar with babashka, so was just seeing if there's any obvious starting points as this seems to be something internal)


Is that macro something from yourself or something from bb?


You're not providing a complete standalone step by step repro. E.g. it is unknown what cleanup does. You haven't said: run this script and then hit ctrl-c or whatever. Having said that, this works for me (bb newest):

(defmacro set-signal-handler!
  [signal f]
    (sun.misc.Signal. ~signal)
    (proxy [sun.misc.SignalHandler] []
      (handle [signal#] (~f signal#)))))

(defn cleanup [_]
  (prn :dude))

(set-signal-handler! "INT" cleanup)
(set-signal-handler! "TERM" cleanup)

The @(promise) prevents the script from exiting. A step by step repro with full context helps sorting out the issue. Any questions/assumptions can be based on that, after the issue is clear


Thanks @U04V15CAJ, in which case, let me dig into the source here and see if I can figure out the issue or I figure out a minimal case!


I mean a repro from a user perspective, not a solution to a problem


If i have an httpkit application in babashka how do i make it run? cause currently when defining a -main function the process just dies 😕 and i have no clue

(defn -main []
  (hk-server/run-server (wrap-params (wrap-session (wrap-anti-forgery #(ruuter/route (routes) %)))) {:port 8080}))
If i start this with bb -m my-app.core or define a task that triggers tha -main function it imidiatly closes


you need to block, since run-server isn't blocking. e.g. add @(promise) to the end of the -main function


aaaaaaaah -.- i'm to dumb -.-


it's a very common source of confusion, don't worry ;)


Will my code be usable in babashka if it uses things like and java.util.Base64? Is everything from java available?


Not everything but those are available


Nice! I glanced at the readme (and saw usage of java.time) but couldn't find a list. Is it written somewhere?


You can see the entire list with this command:

bb -e '(babashka.classes/all-classes)'


Amazing, thank you very much!


👍 If something important is missing, let me know, we can always check if it makes sense to add

👍 2