-
|
I have a function (see below) in a Quart app that counts prime numbers. def count_primes_naive(n: int) -> int:
"""Count number of primes below some number."""
if n < 2:
return 0
count = 0
for x in range(2, n + 1):
is_prime = True
for d in range(2, int(x**0.5) + 1):
if x % d == 0:
is_prime = False
break
if is_prime:
count += 1
return countI use this function in a route as shown here: from quart import Quart
from .primes import count_primes_naive
app = Quart(__name__)
@app.get("/count")
async def count():
n = 1_000_000
p = count_primes_naive(n)
return f"p is {p}"Since the |
Beta Was this translation helpful? Give feedback.
Answered by
catwell
Jan 8, 2026
Replies: 1 comment 8 replies
-
|
count_primes_naive will be called synchronously and block. You should use run_sync. |
Beta Was this translation helpful? Give feedback.
8 replies
Answer selected by
wigging
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
count_primes_naive will be called synchronously and block. You should use run_sync.