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

How to get "trio token" for trio.to_thread.run_sync? #1439

Closed
Nikratio opened this issue Mar 19, 2020 · 4 comments · Fixed by #3001
Closed

How to get "trio token" for trio.to_thread.run_sync? #1439

Nikratio opened this issue Mar 19, 2020 · 4 comments · Fixed by #3001

Comments

@Nikratio
Copy link

Hello,

I am trying to migrate from trio.BlockingTrioPortal to trio.from_thread(). Unfortunately I am running into some trouble because I am trying to call from a not-trio-created thread.

The documentation specifies that I can "pass a keyword argument, trio_token specifiying a specific trio.run loop to re-enter". But how do I get such a token? It doesn't seem mentioned anywhere else (including the description of trio.run).

I think I am looking for a function like trio.get_current_token() whose output I can save and pass to a thread for use with `trio.from_thread.run_sync.

@oremanj
Copy link
Member

oremanj commented Mar 20, 2020

Use trio.hazmat.current_trio_token() from within the Trio thread. For more details, see https://trio.readthedocs.io/en/stable/reference-hazmat.html#trio-tokens

@njsmith
Copy link
Member

njsmith commented Mar 20, 2020

Sounds like the docs could use a small update to point to that?

@Nikratio
Copy link
Author

Yeah, a pointer would be great. I still feels somewhat counterintuitive that I have to fallback on trio.hazmat though, especially because with the old interface that wasn't necessary.

@pquentin
Copy link
Member

@Nikratio We renamed hazmat to lowlevel recently to emphasize the fact that there's nothing wrong with that module :)

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

Successfully merging a pull request may close this issue.

4 participants