Skip to content

to_thread.run_sync() foils meta-class destructors #1638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
belm0 opened this issue Jun 22, 2020 · 2 comments · Fixed by #1639
Closed

to_thread.run_sync() foils meta-class destructors #1638

belm0 opened this issue Jun 22, 2020 · 2 comments · Fixed by #1639

Comments

@belm0
Copy link
Member

belm0 commented Jun 22, 2020

Invoking to_thread.run_sync() seems to prevent meta-class destructors of completely unrelated classes from being called on shutdown.

import trio

class deltype(type):
    def __del__(self):
        print(f"{self.__name__} class deleted")

Test = deltype("Test", (object,), {})

async def async_main():
    await trio.to_thread.run_sync(lambda: print('hi'))
    await trio.sleep(0)

trio.run(async_main)

expected output:

hi
Test class deleted

actual output:

hi

if the run_sync() is commented out, the meta-class destructor is called as expected:

Test class deleted
@smurfix
Copy link
Contributor

smurfix commented Jun 22, 2020

"git bisect" says the thread cache is the culprit.

1d1f871

@smurfix
Copy link
Contributor

smurfix commented Jun 22, 2020

That was reasonably easy ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants