clj-python / clj-python/libpython-clj

NSWindow main thread error when trying to setup Gymnasium (openapi gym)

Aperta
#257 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Clojure
Stelle
1.2k
Fork
74
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi, im trying to run some simple gymnasium stuff and getting the following error:

(require-python '[gymnasium :as gym])
(def env (gym/make "LunarLander-v2" :render_mode "human"))

; error (Temurin java 17) or crash (correto java 17)
(py. env reset :seed 42)

Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:707).
Traceback (most recent call last):
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/wrappers/time_limit.py", line 75, in reset
    return self.env.reset(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/wrappers/order_enforcing.py", line 61, in reset
    return self.env.reset(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/wrappers/env_checker.py", line 57, in reset
    return env_reset_passive_checker(self.env, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/utils/passive_env_checker.py", line 186, in env_reset_passive_checker
    result = env.reset(**kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/envs/box2d/lunar_lander.py", line 461, in reset
    self.render()
  File "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gymnasium/envs/box2d/lunar_lander.py", line 699, in render
    self.screen = pygame.display.set_mode((VIEWPORT_W, VIEWPORT_H))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pygame.error: NSWindow should only be instantiated on the main thread!

I'm on OSX Sonoma (silicon), python 3.11.6, Clojure 1.11.1 and java 17. I was actually about to write this as a crash report, but decided to try another Java 17 jvm and was able to get the error output instead.

In any case, is there something one can do with libpython-clj to setup the call such that it's on the main thread?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'esempio Gymnasium LunarLander con la configurazione Java e macOS segnalata. Esamina libpython-clj2.python.ffi/check-error-throw in ffi.clj:707 e il percorso di chiamata di require-python/py. per la gestione dei thread. Il lavoro è completato quando è stato stabilito se la chiamata può essere eseguita sul thread principale e il comportamento supportato è stato documentato o implementato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
clojure, python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.