sandbox/python/to_thread/wo_to_thread.puml
2026-02-03 09:52:20 +03:00

36 lines
937 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@startuml scenario1_blocking_io
title Синхронная I/O БЕЗ to_thread() - Event Loop заблокирован
participant "Event Loop\n(Main Thread)" as EL
participant GIL
participant "OS Kernel" as OS
note over EL,GIL #FFB6C1: 🔒 GIL удерживается
EL -> EL: async def handler()
EL -> EL: data = requests.get(url) 🚨
note over EL #FFB6C1
**Event Loop ЗАБЛОКИРОВАН!**
Другие async задачи ждут
Тысячи корутин простаивают
end note
EL -> GIL: Удерживает GIL
EL -> OS: socket.recv() (системный вызов)
note over OS
Ядро ОС читает данные
из сети
(это может занять секунды!)
end note
OS --> EL: Данные получены
note over EL #FFD700
Event Loop снова свободен
Но время потеряно!
end note
EL -> EL: return data
@enduml