Skip to content

from_thread.run(_sync)? fails in any thread running Trio #2534

@gschaffner

Description

@gschaffner

hi! from_thread.run(_sync)? uses a heuristic to prevent the user from accidentally deadlocking their event loop by writing code like https://github.com/python-trio/trio/pull/1574/files#r435039316.

the heuristic is currently much more aggressive than is required to prevent this deadlock, however. it has the side-effect1 of preventing one from calling from_thread.run(_sync)? in any thread running trio, even though such calls are almost always safe and deadlock-free.

it would be useful to be able to call from_thread.run(_sync)? from trio threads2, but the current heuristic blindly prevents this. i'd like to propose relaxing from_thread.run(_sync)? to allow calling from_thread.run(_sync)? from trio threads. (one use-case of this is agronholm/anyio#525.)

Footnotes

  1. citing the RuntimeErrors reported in from_thread.run(_sync)?'s docstrings, this would appear to be an unintended side-effect of the current heuristic.

  2. for example in order to call Nursery.start_soon in a thread-safe manner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions