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

Open
Nikratio opened this issue Mar 19, 2020 · 4 comments
Open

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

Nikratio opened this issue Mar 19, 2020 · 4 comments

Comments

@Nikratio
Copy link

@Nikratio Nikratio commented Mar 19, 2020

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 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 njsmith commented Mar 20, 2020

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

@Nikratio
Copy link
Author

@Nikratio Nikratio commented Mar 20, 2020

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

@pquentin pquentin commented May 14, 2020

@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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.