# Can subinterpreters import extension packages?

**URL:** <https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770>\
**Category:** Python Help\
**Created:** [June 14, 2024, 7:20am UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770 "2024-06-14T07:20:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroRains](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/zerorains/32/20458_2.png) [@zeroRains](https://discuss.python.org/u/zeroRains)\
**Post date:** [June 14, 2024, 7:20am UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770/1 "2024-06-14T07:20:40Z")

</div>

I want to know dose subinterpreter which has its GIL can import the extension package? Just like numpy, pyarrow et.al.

---

<div class="post-metadata">

**Author:** ![da-woods](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/da-woods/32/7507_2.png) [@da-woods](https://discuss.python.org/u/da-woods)\
**Post date:** [June 14, 2024, 4:12pm UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770/2 "2024-06-14T16:12:59Z")

</div>

> **[Module Objects](https://docs.python.org/3/c-api/module.html#c.Py_mod_multiple_interpreters)**
>
> Initializing C modules: Modules objects are usually created from extension modules (shared libraries which export an initialization function), or compiled-in modules (where the initialization funct...

The extension modules have to specifically indicate that they support it. I imagine many don’t do this right now.

---

<div class="post-metadata">

**Author:** ![oscarbenjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/oscarbenjamin/32/1209_2.png) [@oscarbenjamin](https://discuss.python.org/u/oscarbenjamin)\
**Post date:** [June 14, 2024, 10:31pm UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770/3 "2024-06-14T22:31:29Z")

</div>

> [@da-woods](#):
>
> The extension modules have to specifically indicate that they support it. I imagine many don’t do this right now.

Does Cython do this automatically or is it something that the author of a Cython module would need to opt in to somehow?

---

<div class="post-metadata">

**Author:** ![zeroRains](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/zerorains/32/20458_2.png) [@zeroRains](https://discuss.python.org/u/zeroRains)\
**Post date:** [June 15, 2024, 1:49am UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770/4 "2024-06-15T01:49:33Z")

</div>

I think we can import the extension modules in the main interpreter. Isn’t there method to share the modules which is imported in main interpreter to sub-interpreter? (If not change the package configration, we may sure the isolation for sub-interpreter) Or will Cpython support this chose?

---

<div class="post-metadata">

**Author:** ![da-woods](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/da-woods/32/7507_2.png) [@da-woods](https://discuss.python.org/u/da-woods)\
**Post date:** [June 15, 2024, 7:27am UTC](https://discuss.python.org/t/can-subinterpreters-import-extension-packages/55770/5 "2024-06-15T07:27:20Z")

</div>

> [@oscarbenjamin](#):
>
> Does Cython do this automatically or is it something that the author of a Cython module would need to opt in to somehow?

Right now Cython doesn’t support it. It requires “isolated module state” - that each sub interpreter has its own copy of the module contents. Some progress has been made on that but not enough for this to work.

If/when it works, I suspect it’ll still be opt-in though. For a “pure-Cython” module then the isolated module state is all you need. However, for anything wrapping an external library it’ll need evaluating by the author.
