Skip to content

Commit

Permalink
Update anyio to_thread import to make pyright happy
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Aug 31, 2023
1 parent b5740ff commit 2b3ae06
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions visyn_core/server/visyn_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import threading
from typing import Any

import anyio
from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from pydantic import create_model
Expand Down Expand Up @@ -164,8 +163,15 @@ def filter(self, record: logging.LogRecord) -> bool:
async def change_anyio_total_tokens():
# FastAPI uses anyio threads to handle sync endpoint concurrently.
# This is a workaround to increase the number of threads to 100, as the default is only 40.
limiter = anyio.to_thread.current_default_thread_limiter()
limiter.total_tokens = manager.settings.visyn_core.total_anyio_tokens
try:
from anyio import to_thread

limiter = to_thread.current_default_thread_limiter()
limiter.total_tokens = manager.settings.visyn_core.total_anyio_tokens
except Exception as e:
_log.exception(
f"Could not set the total number of anyio tokens to {manager.settings.visyn_core.total_anyio_tokens}. Error: {e}"
)

if manager.settings.visyn_core.cypress:
_log.info("Cypress mode is enabled. This should only be used in a Cypress testing environment or CI.")
Expand Down

0 comments on commit 2b3ae06

Please sign in to comment.