Pelokalan
Python ID
id en
Masuk
Proyek
howto__isolating-extensions.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
The key point to keep in mind when developing an extension module is that several module objects can be created from a single shared library. For example:
Sometimes, the state associated with a Python module is not specific to that module, but to the entire process (or something else "more global" than a module). For example:
A non-negative ``PyModuleDef.m_size`` signals that a module supports multiple interpreters correctly. If this is not yet the case for your module, you can explicitly make your module loadable only once per process. For example::
If your module's :c:member:`PyModuleDef.m_clear` function is able to prepare for future re-initialization, it should clear the ``loaded`` flag. In this case, your module won't support multiple instances existing *concurrently*, but it will, for example, support being loaded after Python runtime shutdown (:c:func:`Py_FinalizeEx`) and re-initialization (:c:func:`Py_Initialize`).
Such types are necessarily shared across the process. Sharing them between module objects requires paying attention to any state they own or access. To limit the possible issues, static types are immutable at the Python level: for example, you can't set ``str.myattribute = 123``.
For example, if your traverse function includes::
To keep the type valid while ``tp_free`` is called, the type's refcount needs to be decremented *after* the instance is deallocated. For example::
For example::
Sebagai contoh::