Avoid generation gets hanging when user specifies multiple event loops (#5162)

Co-authored-by: Yineng Zhang <me@zhyncs.com>
This commit is contained in:
fzyzcjy
2025-10-19 16:12:49 +08:00
committed by GitHub
parent a27825ae01
commit 002d037359

View File

@@ -267,7 +267,7 @@ class TokenizerManager(TokenizerCommunicatorMixin):
)
# Request states
self.no_create_loop = False
self._chosen_loop = None
self.rid_to_state: Dict[str, ReqState] = {}
self.asyncio_tasks = set()
@@ -1170,11 +1170,14 @@ class TokenizerManager(TokenizerCommunicatorMixin):
return background_tasks
def auto_create_handle_loop(self):
if self.no_create_loop:
if self._chosen_loop is not None:
assert (
asyncio.get_event_loop() == self._chosen_loop
), f"Please ensure only one event loop is ever used with SGLang. Previous loop: {self._chosen_loop}, current loop: {asyncio.get_event_loop()}"
return
self.no_create_loop = True
loop = asyncio.get_event_loop()
self._chosen_loop = loop
self.asyncio_tasks.add(
loop.create_task(print_exception_wrapper(self.handle_loop))
)