Modernize code to Python 3.6+ and some cleanup
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import math
|
||||
import itertools
|
||||
|
||||
|
||||
PRIME_FIXTURE = [
|
||||
@@ -36,7 +35,7 @@ def is_prime(n) -> bool:
|
||||
if n % 2 == 0:
|
||||
return False
|
||||
|
||||
root = int(math.floor(math.sqrt(n)))
|
||||
root = math.floor(math.sqrt(n))
|
||||
for i in range(3, root + 1, 2):
|
||||
if n % i == 0:
|
||||
return False
|
||||
|
||||
@@ -34,10 +34,10 @@ def main() -> None:
|
||||
label = 'P' if prime else ' '
|
||||
print(f'{n:16} {label} {elapsed:9.6f}s')
|
||||
|
||||
|
||||
time = perf_counter() - t0
|
||||
print('Total time:', f'{time:0.2f}s')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
# end::PRIMES_PROC_MAIN[]
|
||||
|
||||
@@ -18,7 +18,7 @@ async def is_prime(n):
|
||||
return False
|
||||
|
||||
sleep = asyncio.sleep # <1>
|
||||
root = int(math.floor(math.sqrt(n)))
|
||||
root = math.floor(math.sqrt(n))
|
||||
for i in range(3, root + 1, 2):
|
||||
if n % i == 0:
|
||||
return False
|
||||
|
||||
@@ -18,7 +18,7 @@ async def is_prime(n):
|
||||
return False
|
||||
|
||||
sleep = asyncio.sleep # <1>
|
||||
root = int(math.floor(math.sqrt(n)))
|
||||
root = math.floor(math.sqrt(n))
|
||||
for i in range(3, root + 1, 2):
|
||||
if n % i == 0:
|
||||
return False
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
from multiprocessing import Process, Event
|
||||
from multiprocessing import synchronize
|
||||
import itertools
|
||||
import time
|
||||
|
||||
from primes import is_prime
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
from threading import Thread, Event
|
||||
import itertools
|
||||
import time
|
||||
|
||||
from primes import is_prime
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# tag::SPINNER_THREAD_TOP[]
|
||||
from threading import Thread, Event
|
||||
import itertools
|
||||
import time
|
||||
|
||||
from primes import is_prime
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from time import perf_counter
|
||||
from typing import Tuple, List, NamedTuple
|
||||
from typing import List, NamedTuple
|
||||
from threading import Thread
|
||||
from queue import SimpleQueue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user