# Python3.12 user-defined immortal objects

**URL:** <https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115>\
**Category:** Python Help\
**Tags:** documentation, help\
**Created:** [September 19, 2023, 2:57pm UTC](https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115 "2023-09-19T14:57:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zihan-j-zhao](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/zihan-j-zhao/32/14748_2.png) [@zihan-j-zhao](https://discuss.python.org/u/zihan-j-zhao)\
**Post date:** [September 19, 2023, 2:57pm UTC](https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115/1 "2023-09-19T14:57:17Z")

</div>

The concept of immortal objects was introduced since [PEP 683](https://peps.python.org/pep-0683/). I saw many internal objects (such as small ints, None, strings, etc.) have been made immortal, but I wonder if it is possible to make a user-defined object immortal in the current Python versions? If not, what could be a workaround?

For example,

```auto
class MyClass:
    def __init__ (self, x):
        self._x = x

mycls = MyClass(3)
# Does there exist or would there be some public API to make `mycls` immortal?
sys.setimmortal(mycls) # for example

```

---

<div class="post-metadata">

**Author:** ![franklinvp](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/franklinvp/32/11142_2.png) [@franklinvp](https://discuss.python.org/u/franklinvp)\
**Post date:** [September 19, 2023, 5:08pm UTC](https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115/2 "2023-09-19T17:08:41Z")

</div>

I do not know, but in the Scope section it says

> Object immortality is meant to be an internal-only feature, so this proposal does not include any changes to public API or behavior (with one exception).

---

<div class="post-metadata">

**Author:** ![zihan-j-zhao](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/zihan-j-zhao/32/14748_2.png) [@zihan-j-zhao](https://discuss.python.org/u/zihan-j-zhao)\
**Post date:** [September 19, 2023, 5:25pm UTC](https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115/3 "2023-09-19T17:25:26Z")

</div>

Thanks for the info!

---

<div class="post-metadata">

**Author:** ![Erotemic](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erotemic/32/8025_2.png) [@Erotemic](https://discuss.python.org/u/Erotemic)\
**Post date:** [May 30, 2025, 1:28am UTC](https://discuss.python.org/t/python3-12-user-defined-immortal-objects/34115/4 "2025-05-30T01:28:02Z")

</div>

Is there discussion about adding this as a public API? It would be very useful for pytorch datalaoders with nested data structures. You want them to live forever, and the reference counting wrecks copy-on-write havoc.

EDIT: I see a discussion here: [Exposing public APIs for immortal objects](https://discuss.python.org/t/exposing-public-apis-for-immortal-objects/64264)
