Cross-language issues¶
Multi-threading¶
Chaquopy is thread-safe. However, because it’s based on CPython (the Python reference implementation), it is limited by CPython’s global interpreter lock (GIL). This means that although Python code may be run on any number of threads, only one of those threads will be executing at any given moment.
threading.main_thread
will return the thread on which Python was started. Depending on
your app’s structure, this might not be the same as the main thread in Java.
See also
The multi-threading features of the Python API.
Memory management¶
It’s possible to create a cross-language reference cycle if a Python object references a Java object which, directly or indirectly, references the original Python object. Such a cycle cannot be detected by the garbage collector in either language. To avoid a memory leak. either use a weak reference somewhere in the cycle, or break the cycle manually once it’s no longer required.