How can I call python functions that rely on "event_loop" inside go blocks?
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginne mit dem minimalen core.async-go-Beispiel aus dem Issue und dem Traceback, der zeigt, dass asyncio.get_event_loop auf einem Dummy thread ausgeführt wird. Lies den Python-Aufrufpfad von libpython-clj2 und den Ausführungskontext von core.async go, um festzustellen, ob der Zugriff auf die Event-Loop unterstützt werden kann. Die Aufgabe wäre abgeschlossen, wenn es eine dokumentierte, funktionierende Möglichkeit gibt, diese Python-Funktionen aus go-Blöcken aufzurufen, oder eine klare Erklärung, dass dieser Ansatz nicht unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Huge thanks for the great library. I'm wondering if the following is possible.
The problem
I want to call python functions with asyncio.get_event_loop() inside go blocks.
The get_event_loop is buried deep in the python code base, so I can't simply swap every required event loop to some new event loop that I create.
I haven't come up with a way to write a wrapper, and setting the event loop manually does not help.
I'm not seeking to solve the exception, because I think my approach seems wrong and the exception is expected, but rather, I'm asking for a way for my goal.
Many Thanks!
A minimal example that crashes
(ns main.playasync
(:require [libpython-clj2.require :refer [require-python]]
[libpython-clj2.python :refer [py. py.. py.-] :as py]
[clojure.core.async :as async :refer [>! <! chan go]]))
(require-python '[agen]
'[builtins :as python]
'[asyncio])
(comment
(go
(let [ev-loop (asyncio/new_event_loop)]
(asyncio/set_event_loop ev-loop)
(asyncio/get_event_loop))))
will raise an exception
Exception in thread "async-dispatch-6" java.lang.Exception: Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Dummy-6'.
at libpython_clj2.python.ffi$check_error_throw.invokeStatic(ffi.clj:703)
at libpython_clj2.python.ffi$check_error_throw.invoke(ffi.clj:701)
at libpython_clj2.python.ffi$simplify_or_track.invokeStatic(ffi.clj:960)
at libpython_clj2.python.ffi$simplify_or_track.invoke(ffi.clj:941)
at libpython_clj2.python.fn$call_py_fn.invokeStatic(fn.clj:197)
at libpython_clj2.python.fn$call_py_fn.invoke(fn.clj:177)
at libpython_clj2.python.bridge_as_jvm$generic_callable_pyobject$reify__17712.call(bridge_as_jvm.clj:427)
at libpython_clj2.python.fn$call_kw.invokeStatic(fn.clj:217)
at libpython_clj2.python.fn$call_kw.invoke(fn.clj:214)
at libpython_clj2.python.fn$cfn.invokeStatic(fn.clj:282)
at libpython_clj2.python.fn$cfn.doInvoke(fn.clj:273)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at libpython_clj2.python.bridge_as_jvm$generic_callable_pyobject$reify__17712.invoke(bridge_as_jvm.clj:427)
at main.playasync$eval31361$fn__31362$state_machine__28343__auto____31363$fn__31365.invoke(NO_SOURCE_FILE:14)
at main.playasync$eval31361$fn__31362$state_machine__28343__auto____31363.invoke(NO_SOURCE_FILE:11)
at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:978)
at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:977)
at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:982)
at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:980)
at main.playasync$eval31361$fn__31362.invoke(NO_SOURCE_FILE:11)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at clojure.core.async.impl.concurrent$counted_thread_factory$reify__22117$fn__22118.invoke(concurrent.clj:29)
at clojure.lang.AFn.run(AFn.java:22)
at java.base/java.lang.Thread.run(Thread.java:833)
- Vorherrschende Sprache
- Clojure
- Sterne
- 1.2k
- Forks
- 74
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus clj-python/libpython-clj
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
clj-python/libpython-clj#280 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
clj-python/libpython-clj#275 · 5 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 58/100
clj-python/libpython-clj#273 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
clj-python/libpython-clj#271 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
clj-python/libpython-clj#270 · 1 Kommentar ·
Alle Issues in clj-python/libpython-clj
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
-
.Team/Metabot Priority:P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
needs triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
scalar-labs/scalar-jepsen#222 · 1 Kommentar ·