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.)
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 relaxingfrom_thread.run(_sync)?to allow callingfrom_thread.run(_sync)?from trio threads. (one use-case of this is agronholm/anyio#525.)Footnotes
citing the
RuntimeErrors reported infrom_thread.run(_sync)?'s docstrings, this would appear to be an unintended side-effect of the current heuristic. ↩for example in order to call
Nursery.start_soonin a thread-safe manner. ↩