[英]Clojure create python runtime and execute task
我想用Clojure編寫一個程序,該程序具有Python運行時並接受Python函數代碼,並通過套接字從某些客戶端將此函數的參數列表列出,然后將其添加到運行時,並使用參數調用它並返回結果給客戶。
我想知道如何:
您可以為此使用clojure.java.shell
:
(ns tst.clj.core
(:require [clojure.java.shell :as shell] ))
(t/refer-tupelo)
(t/print-versions)
(println (shell/sh "python" "-c" "print (2 + 3)" ))
;=> {:exit 0, :out "5\n", :err ""}
如果您擔心啟動Python的開銷,那么似乎只有6毫秒:
(time
(let [sum-vec (for [i (range 100)]
(Integer/parseInt (str/trim (:out (shell/sh "python" "-c" (format "print (%d + 3)" i))))))
cumsum (reduce + sum-vec)
]
(println :cumsum cumsum)))
;=> :cumsum 5250
;=> "Elapsed time: 638.612278 msecs"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.