Skip to content
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

Destructors aren't run for detached tasks #294

Closed
vojtechkral opened this issue Jan 6, 2024 · 5 comments · Fixed by #312
Closed

Destructors aren't run for detached tasks #294

vojtechkral opened this issue Jan 6, 2024 · 5 comments · Fixed by #312
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@vojtechkral
Copy link

I noticed today that when I .detach() a task, its drop() is never run.
Is this to be expected?
If yes, this should probably be documented in Task::detach() docs...

Using smol v1.3.0.

@notgull
Copy link
Member

notgull commented Jan 6, 2024

Tasks spawned with smol::spawn and detached are never dropped, this should be noted in that method's documentation. On the other hand, if you spawn tasks with a normal executor they should be dropped when the executor's destructor runs.

@vojtechkral
Copy link
Author

It looks like when I don't detach the task, the drop() is only run sometimes. I'm quite confused.

Looks like I have to .cacnel().await, then it runs the dtor for sure.

@notgull
Copy link
Member

notgull commented Jan 6, 2024

This is to be expected. The executor in this case is 'static and static types don't always run their destructors.

The intended solution is to create your own executor.

@vojtechkral
Copy link
Author

Ah, okay.

I can PR the docs change for .detach() if you'd like...

@notgull
Copy link
Member

notgull commented Jan 6, 2024

Yes, that would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
2 participants