MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / is_prime

Function is_prime

19-concurrency/primes/spinner_prime_async_nap.py:13–27  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

11
12# tag::PRIME_NAP[]
13async def is_prime(n):
14 if n < 2:
15 return False
16 if n == 2:
17 return True
18 if n % 2 == 0:
19 return False
20
21 root = math.isqrt(n)
22 for i in range(3, root + 1, 2):
23 if n % i == 0:
24 return False
25 if i % 100_000 == 1:
26 await asyncio.sleep(0) # <1>
27 return True
28# end::PRIME_NAP[]
29
30

Callers 1

checkFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected