You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
Free-threaded CPython and threads that start the JVM together: serialize start_jvm(), define the JPype proxy classes once, add a thread stress test #453
Threads whose first call is create_database() or open_database() race into jpype.startJVM, and a free-threaded CPython (no GIL) shows more races. We ran the bindings on 3.14.5 free-threaded (PYTHON_GIL=0, JPype 1.7.1, which publishes cp313t and cp314t wheels and keeps the GIL off) against 3.14.5 with the GIL as the control, with a new stress test that runs many threads against one database and one database each and compares the result with a sequential run.
Two bugs in the bindings, both fixed on the branch ft-free-threading:
start_jvm() checks isJVMStarted() and then calls startJVM() with no lock. With 16 threads that all start with create_database() or open_database(), 3 of 3 runs failed with Failed to start JVM: JVM is already started on ordinary 3.14 with the GIL, so this is a bug for every user who starts the first call from several threads, not only on free-threaded builds. On 3.14t all but one thread got Unable to start JVM. The fix is a lock around start_jvm(); the threads that lose the race take the "JVM already started" branch. After the fix 12 of 12 runs were clean on each interpreter.
callbacks._function_proxy_class() and _event_proxy_class() check the cache and then define the @JImplements class. 16 threads that register their first function together defined 10 to 16 classes, and each one leaks, which is why the cache exists. 5 of 5 repeats of the new scenario failed before the fix and 5 of 5 pass with the definition under a lock and a second check.
Open, not fixable in the bindings, to document on the Known Engine Issues page:
Rare SIGSEGV in JPype's JPHintsConversion::matches when several threads make their first Java calls together: 2 of 30 first-start runs on 3.14t, 0 of 27 with the GIL. A warm-up (open a database and run one statement on the main thread before the workers start) is the obvious precaution and is not verified.
A process in which a non-main thread used Java does not exit (Advice: Threading and JPype - JVM never ends jpype-project/jpype#1169), on every Python, with or without the GIL. jpype.java.lang.Thread.detach() at the end of the thread, or jpype.config.destroy_jvm = False (which skips the JVM shutdown hooks), make it exit. The bindings keep JPype's default.
The native backend needed no change: its shared state is per call, per thread or behind a lock, and 0 of the repeats failed on either interpreter.
Activity