This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-29
Channels
- # announcements (4)
- # babashka (66)
- # beginners (7)
- # cljs-dev (6)
- # clojure (12)
- # clojure-europe (28)
- # clojure-nl (1)
- # clojure-norway (75)
- # clojure-uk (16)
- # clojuredesign-podcast (1)
- # clojurescript (16)
- # datascript (6)
- # deps-new (2)
- # dev-tooling (40)
- # exercism (1)
- # fulcro (92)
- # hyperfiddle (25)
- # lsp (19)
- # malli (1)
- # meander (2)
- # nrepl (9)
- # off-topic (5)
- # pathom (1)
- # practicalli (1)
- # re-frame (20)
- # reitit (14)
- # releases (1)
- # sci (86)
- # shadow-cljs (216)
- # sql (13)
- # testing (4)
- # tools-deps (4)
- # vscode (3)
Quick check, is this the intended behavior for $HOME or an otherwise empty / non-bb-specific dir?
~ $ bb
Babashka v1.3.185 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (System/getProperty "java.class.path")
""
(It's not causing big trouble but it's the first time I see an empty classpath)That sounds about right. bb looks at https://github.com/babashka/babashka/blob/master/src/babashka/impl/classpath.clj#L80 places for the classpath and defaults to empty. What was your expectation?
according to https://github.com/babashka/babashka/blob/master/src/babashka/impl/classpath.clj#L83 it gives a blank str?
i guess that would also work with nil
ive always used babashka.classpath/get-classpath
for this which gave nil, so not sure
Ok for a minute I thought I introduced a regressed in the new release but all good then
Don’t know why it would be an empty string if it wasn’t set yet though, I would expect nil
i tried looking for it, not sure where could it be
right, native-image/SubstrateVM seems to have it default to ""
native compile:
System.out.println("'%s' is the classpath".formatted(System.getProperty("java.class.path")));
thats whats probably happening in bb
public class Foo {
public static void main(String... args) {
System.out.println(System.getProperty("java.class.path").length()); // => 0
}
}
System.getProperty("this.doesnt.exist")
gives null
do we need the new SCI feature to make this return nil too? 😛 that would probably a breaking change
We can just set it to nil manually at startup but if it isn’t causing any bugs I would just let it be
Hmm might be interesting to actually use the new SCI feature for this to intercept the call but maybe wait a bit
jshell> System.getProperty("java.class.path")
$1 ==> "."
Apparently they can't live with a non-classpath.
sounds reasonable since a file under $PWD is reasonable to be considered to be on the classpath, if nothing else was specified
(expanding .
to an absolute file name would probably be nicer to clients)
However, I'm not experiencing a problem, I just assessed cider <-> bb integration (fixing a couple things while I was there) and wanted to make sure there are no weird corners
I have considered adding the PWD as the default classpath if nothing else was specified but so far I haven't made that decision yet. https://github.com/babashka/babashka/issues/1555
the default PWD seems to be specific to Java? Clojure, Kotlin, Scala all say different things
whatever GraalVM has set as a default, this does not affect how bb really works, since the system property is a mere reflection of the reality inside bb, not the source of truth
I have a clojure (JVM) process which starts a Chromium process through Playwright. I also want to create a babashka task that runs this clojure process, so that I can potentially react to log messages in the JVM process. The problem is, if I shut down the babashka process with CTRL+C, the JVM process gets terminated but there is some Error: write EPIPE
probably from Chromium (and next timke Chromium starts, it says it wasn't shut down correctly). This does not happen if I run the JVM process manually from bash. So I'm wondering if the babashka shell
and babashka.process/process
functions pass the correct termination signals to the JVM, or why is this happening?
I've tried these bb tasks, which behave similarly:
runl1 (shell {:extra-env {"XTDB_ENABLE_BYTEUTILS_SHA1" true}}
"clojure -A:web -X uxa.backend/main")
runl2 (-> (p/process ["clojure" "-A:web" "-X" "uxa.backend/main"]
{:extra-env {:XTDB_ENABLE_BYTEUTILS_SHA1 "true"}
:inherit true
:shutdown p/destroy-tree})
(p/check))
this won't solve your issue but for consistency: add the map as the first argument to process and the other arguments can be spliced as just string after that
what you are doing with process is pretty similar to shell
btw, exactly the same even I think
do you mean: when you quit bb, it should send SIGKILL or SIGINT to the running processes?
you could try this manually by adding a Shutdown hook which sends SIGINT to those processes... I'm not sure if the JVM / GraalVM does that by default
ok, thanks, i'll try to figure out how to do that. btw wrapping the commands in bash -c '...'
did not solve it
(def proc (babashka.process/process {:inherit true} "yes"))
(.addShutdownHook (Runtime/getRuntime)
(Thread. ^java.lang.Runnable (fn [] (babashka.process/destroy proc))))
I noticed that when you don't add the shutdown hook and destroy the process, the process keeps running
oh wait, but this is exactly the same as (def proc (babashka.process/process {:inherit true :shutdown babashka.process/destroy} "yes"))
and seems to work correctly with:
(def proc (babashka.process/process {:inherit true :shutdown babashka.process/destroy} "yes"))
(Thread/sleep 10000)
so perhaps destroy
isn't the right thing to send to your process for some reason, luckily it's configurable
you can view the process builder API here: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Process.html
you can get the raw process using (:proc proc)
and then try some Java interop. Not sure
though .destroy sounds like it would send SIGINT and destroyForcibly would send SIGTERM
OK I think I know what's happening. I was using :shutdown p/destroy-tree
, which was sending SIGINT (?) to both the JVM process and the Chromium process (duh, since it's destroy-tree). But the clean way for handling this was to send :shutdown p/destroy
, which sends SIGINT to just the JVM which in turn has a chance to shut down the Chromium process cleanly. So babashka was working entirely as expected, my bad!
But thanks for the quick replies and all the amazing open source contributions! 🙌
Hey! I have this code that works with clj-http:
(defonce cookie-store
(doto
(clj-http.cookies/cookie-store)
(as-> cookie-store
(binding [clj-http.core/*cookie-store* cookie-store]
(http/post ""
{:form-params {:username "user"
:password "password"}
:headers {:referer ""}})))))
(comment (http/get ""
{:cookie-store cookie-store
:headers {:referer ""}}))
Can you help me understand how to do that with babashka.http-client
?
I found ->CookieHandler
but I can't figure out how to use it. I haven't found any examples either.
https://github.com/babashka/http-client/blob/dc8ae30a5f52f1e1546755a7ec9984f25268c8c5/src/babashka/http_client.clj#L46-L54
Thanks!Although, this does work fine. I'm happy.
(def cookie (-> (http/post ""
{:form-params {:username "user"
:password "password"}
:headers {:referer ""}})
:headers
(update-keys csk/->kebab-case-keyword)
:set-cookie))
(http/get ""
{:headers {:referer ""
:cookie cookie}})
@UPD88PGNT did you find your answer?
you can pass this https://github.com/babashka/http-client/blob/main/API.md#babashka.http-client/-%3ECookieHandler to your client
if you will then re-use the same client over and over, it will manage the cookies for you