TGViewer
Находки в опенсорсе Находки в опенсорсе @opensource_findings · 12.6K subscribers
Post #589 3.26K
​​Unsynchronize asyncio by using an ambient event loop in a separate #python thread.

- Mark all async functions with @unsync. May also mark regular functions to execute in a separate thread.
- - All @unsync functions, async or not, return an Unfuture

- All Futures must be Unfutures which includes the result of an @unsync function call, or wrapping Unfuture(asyncio.Future) or Unfuture(concurrent.Future). Unfuture combines the behavior of asyncio.Future and concurrent.Future:
- - Unfuture.setvalue is threadsafe unlike asyncio.Future
- - Unfuture instances can be awaited, even if made from concurrent.Future
- - Unfuture.result() is a blocking operation except in unsync.loop/unsync.thread where it behaves like asyncio.Future.result and will throw an exception if the future is not done

- Functions will execute in different contexts:
- -
@unsync async functions will execute in an event loop in unsync.thread
- -
@unsync regular functions will execute in unsync.threadexecutor, a ThreadPoolExecutor
- - @unsync(cpubound=True) regular functions will execute in unsync.processexecutor, a ProcessPoolExecutor

https://github.com/alex-sherman/unsync
More from @opensource_findings
  1. Oct 9, 2026Post #990
  2. Sep 28, 2026Еще анонсы докладов на бесплатную конференцию 17 октября в НН Регистрация: https://itgorky…
  3. Sep 25, 2026Монадические выражения в Python. Наконец-то! Продолжаем разговор про интересные PEPы. Пого…
  4. Sep 15, 2026PEPы в Python окончательно вышли из-под контроля Давайте посмотрим, что происходит с ПЕПам…
  5. Sep 10, 2026Большая бесплатная конференция в Нижнем Новгороде 17 октября Регистрация: https://itgorky.…
  6. Sep 1, 2026Post #985
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →