diff --git a/src/04-asyncio/loops/loops_asyncio/loop_program.py b/src/04-asyncio/loops/loops_asyncio/loop_program.py index 4569cfb..b746451 100644 --- a/src/04-asyncio/loops/loops_asyncio/loop_program.py +++ b/src/04-asyncio/loops/loops_asyncio/loop_program.py @@ -5,10 +5,13 @@ def main(): lim = 250_000 - print("Running standard loop with {:,} actions.".format(lim*2)) + print(f"Running standard loop with {lim * 2:,} actions.") t0 = datetime.datetime.now() - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() + data = asyncio.Queue() task1 = loop.create_task(generate_data(lim, data)) @@ -19,7 +22,7 @@ def main(): loop.run_until_complete(final_task) dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) async def generate_data(num: int, data: asyncio.Queue): diff --git a/src/04-asyncio/loops/loops_uv/loop_program_uv.py b/src/04-asyncio/loops/loops_uv/loop_program_uv.py index 570d0c7..c32747e 100644 --- a/src/04-asyncio/loops/loops_uv/loop_program_uv.py +++ b/src/04-asyncio/loops/loops_uv/loop_program_uv.py @@ -8,10 +8,12 @@ def main(): lim = 250000 - print("Running standard loop with {:,} actions.".format(lim * 2)) + print(f"Running standard loop with {lim * 2:,} actions.") t0 = datetime.datetime.now() - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() data = asyncio.Queue() task1 = loop.create_task(generate_data(lim, data)) @@ -22,7 +24,7 @@ def main(): loop.run_until_complete(final_task) dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) async def generate_data(num: int, data: asyncio.Queue): diff --git a/src/04-asyncio/producer_consumer/prod_async/async_program.py b/src/04-asyncio/producer_consumer/prod_async/async_program.py index 4ae98f8..bbf32d1 100644 --- a/src/04-asyncio/producer_consumer/prod_async/async_program.py +++ b/src/04-asyncio/producer_consumer/prod_async/async_program.py @@ -5,8 +5,9 @@ def main(): - - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() t0 = datetime.datetime.now() print(colorama.Fore.WHITE + "App started.", flush=True) @@ -21,7 +22,7 @@ def main(): loop.run_until_complete(final_task) dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) async def generate_data(num: int, data: asyncio.Queue): @@ -29,7 +30,7 @@ async def generate_data(num: int, data: asyncio.Queue): item = idx*idx await data.put((item, datetime.datetime.now())) - print(colorama.Fore.YELLOW + " -- generated item {}".format(idx), flush=True) + print(colorama.Fore.YELLOW + f" -- generated item {idx}", flush=True) await asyncio.sleep(random.random() + .5) @@ -44,7 +45,7 @@ async def process_data(num: int, data: asyncio.Queue): dt = datetime.datetime.now() - t print(colorama.Fore.CYAN + - " +++ Processed value {} after {:,.2f} sec.".format(value, dt.total_seconds()), flush=True) + f" +++ Processed value {value} after {dt.total_seconds():,.2f} sec.", flush=True) await asyncio.sleep(.5) diff --git a/src/04-asyncio/producer_consumer/prod_sync/sync_program.py b/src/04-asyncio/producer_consumer/prod_sync/sync_program.py index 2ecef0c..1530d95 100644 --- a/src/04-asyncio/producer_consumer/prod_sync/sync_program.py +++ b/src/04-asyncio/producer_consumer/prod_sync/sync_program.py @@ -12,7 +12,7 @@ def main(): process_data(20, data) dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) def generate_data(num: int, data: list): @@ -20,7 +20,7 @@ def generate_data(num: int, data: list): item = idx*idx data.append((item, datetime.datetime.now())) - print(colorama.Fore.YELLOW + " -- generated item {}".format(idx), flush=True) + print(colorama.Fore.YELLOW + f" -- generated item {idx}", flush=True) time.sleep(random.random() + .5) @@ -38,7 +38,7 @@ def process_data(num: int, data: list): dt = datetime.datetime.now() - t print(colorama.Fore.CYAN + - " +++ Processed value {} after {:,.2f} sec.".format(value, dt.total_seconds()), flush=True) + f" +++ Processed value {value} after {dt.total_seconds():,.2f} sec.", flush=True) time.sleep(.5) diff --git a/src/04-asyncio/web_scraping/async_scrape/program.py b/src/04-asyncio/web_scraping/async_scrape/program.py index 58984fa..e82a075 100644 --- a/src/04-asyncio/web_scraping/async_scrape/program.py +++ b/src/04-asyncio/web_scraping/async_scrape/program.py @@ -36,7 +36,9 @@ def main(): t0 = datetime.datetime.now() global loop - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() loop.run_until_complete(get_title_range()) dt = datetime.datetime.now() - t0 @@ -55,7 +57,7 @@ async def get_title_range(): # Please keep this range pretty small to not DDoS my site. ;) tasks = [] - for n in range(150, 160): + for n in range(375, 385): tasks.append((n, loop.create_task(get_html(n)))) for n, t in tasks: diff --git a/src/04-asyncio/web_scraping/sync_scrape/program.py b/src/04-asyncio/web_scraping/sync_scrape/program.py index cb5ac39..c37d8b0 100644 --- a/src/04-asyncio/web_scraping/sync_scrape/program.py +++ b/src/04-asyncio/web_scraping/sync_scrape/program.py @@ -34,7 +34,7 @@ def main(): def get_title_range(): # Please keep this range pretty small to not DDoS my site. ;) - for n in range(150, 160): + for n in range(375, 385): html = get_html(n) title = get_title(html, n) print(Fore.WHITE + f"Title found: {title}", flush=True) diff --git a/src/05-threads/basic_threads/sync_prod.py b/src/05-threads/basic_threads/sync_prod.py index 17353b8..cf5c875 100644 --- a/src/05-threads/basic_threads/sync_prod.py +++ b/src/05-threads/basic_threads/sync_prod.py @@ -14,7 +14,7 @@ def main(): process_data(40, data) dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) def generate_data(num: int, data: list): @@ -40,7 +40,7 @@ def process_data(num: int, data: list): dt = datetime.datetime.now() - t print(colorama.Fore.CYAN + - " +++ Processed value {} after {:,.2f} sec.".format(value, dt.total_seconds()), flush=True) + f" +++ Processed value {value} after {dt.total_seconds():,.2f} sec.", flush=True) time.sleep(.5) diff --git a/src/05-threads/basic_threads/threaded_prod.py b/src/05-threads/basic_threads/threaded_prod.py index ad8bc90..62224c3 100644 --- a/src/05-threads/basic_threads/threaded_prod.py +++ b/src/05-threads/basic_threads/threaded_prod.py @@ -28,7 +28,7 @@ def main(): break dt = datetime.datetime.now() - t0 - print(colorama.Fore.WHITE + "App exiting, total time: {:,.2f} sec.".format(dt.total_seconds()), flush=True) + print(colorama.Fore.WHITE + f"App exiting, total time: {dt.total_seconds():,.2f} sec.", flush=True) def check_cancel(): @@ -62,7 +62,7 @@ def process_data(num: int, data: list): dt = datetime.datetime.now() - t print(colorama.Fore.CYAN + - " +++ Processed value {} after {:,.2f} sec.".format(value, dt.total_seconds()), flush=True) + f" +++ Processed value {value} after {dt.total_seconds():,.2f} sec.", flush=True) time.sleep(.5) diff --git a/src/05-threads/cpu_attempt/compute_it.py b/src/05-threads/cpu_attempt/compute_it.py index 415471e..e3d7900 100644 --- a/src/05-threads/cpu_attempt/compute_it.py +++ b/src/05-threads/cpu_attempt/compute_it.py @@ -10,7 +10,7 @@ def main(): do_math(num=30000000) dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") def do_math(start=0, num=10): diff --git a/src/05-threads/cpu_attempt/compute_threaded.py b/src/05-threads/cpu_attempt/compute_threaded.py index 59d8dab..20e73f3 100644 --- a/src/05-threads/cpu_attempt/compute_threaded.py +++ b/src/05-threads/cpu_attempt/compute_threaded.py @@ -10,7 +10,7 @@ def main(): t0 = datetime.datetime.now() # do_math(num=30000000) - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") processor_count = multiprocessing.cpu_count() threads = [] @@ -25,7 +25,7 @@ def main(): [t.join() for t in threads] dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") def do_math(start=0, num=10): diff --git a/src/05-threads/hello_threads/hello.py b/src/05-threads/hello_threads/hello.py index 4585c4b..2756eb0 100644 --- a/src/05-threads/hello_threads/hello.py +++ b/src/05-threads/hello_threads/hello.py @@ -22,7 +22,7 @@ def main(): def greeter(name: str, times: int): for n in range(0, times): - print("{}. Hello there {}".format(n, name)) + print(f"{n}. Hello there {name}") time.sleep(1) diff --git a/src/06-thread-safety/safe_bank.py b/src/06-thread-safety/safe_bank.py index 800a088..06c99f6 100644 --- a/src/06-thread-safety/safe_bank.py +++ b/src/06-thread-safety/safe_bank.py @@ -32,7 +32,7 @@ def main(): dt = datetime.datetime.now() - t0 - print("Transfers complete ({:,.2f}) sec".format(dt.total_seconds())) + print(f"Transfers complete ({dt.total_seconds():,.2f}) sec") validate_bank(accounts, total) @@ -87,8 +87,7 @@ def validate_bank(accounts: List[Account], total: int, quiet=False): current, total ), flush=True) elif not quiet: - print("All good: Consistent account balance: ${:,}".format( - total), flush=True) + print(f"All good: Consistent account balance: ${total:,}", flush=True) def get_two_accounts(accounts): diff --git a/src/06-thread-safety/safe_bank_fine_grained.py b/src/06-thread-safety/safe_bank_fine_grained.py index c786964..83be9dc 100644 --- a/src/06-thread-safety/safe_bank_fine_grained.py +++ b/src/06-thread-safety/safe_bank_fine_grained.py @@ -33,7 +33,7 @@ def main(): dt = datetime.datetime.now() - t0 - print("Transfers complete ({:,.2f}) sec".format(dt.total_seconds())) + print(f"Transfers complete ({dt.total_seconds():,.2f}) sec") validate_bank(accounts, total) @@ -91,7 +91,7 @@ def validate_bank(accounts: List[Account], total: int, quiet=False): # with transfer_lock: # current = sum(a.balance for a in accounts) - [a.lock.acquire() for a in accounts] + [a.lock.acquire() for a in sorted(accounts, key=lambda x: id(x))] current = sum(a.balance for a in accounts) [a.lock.release() for a in accounts] @@ -100,8 +100,7 @@ def validate_bank(accounts: List[Account], total: int, quiet=False): current, total ), flush=True) elif not quiet: - print("All good: Consistent account balance: ${:,}".format( - total), flush=True) + print(f"All good: Consistent account balance: ${total:,}", flush=True) def get_two_accounts(accounts): diff --git a/src/06-thread-safety/unsafe_bank.py b/src/06-thread-safety/unsafe_bank.py index 518d16f..45f9096 100644 --- a/src/06-thread-safety/unsafe_bank.py +++ b/src/06-thread-safety/unsafe_bank.py @@ -32,7 +32,7 @@ def main(): dt = datetime.datetime.now() - t0 - print("Transfers complete ({:,.2f}) sec".format(dt.total_seconds())) + print(f"Transfers complete ({dt.total_seconds():,.2f}) sec") validate_bank(accounts, total) @@ -71,8 +71,7 @@ def validate_bank(accounts: List[Account], total: int, quiet=False): current, total ), flush=True) elif not quiet: - print("All good: Consistent account balance: ${:,}".format( - total), flush=True) + print(f"All good: Consistent account balance: ${total:,}", flush=True) def get_two_accounts(accounts): diff --git a/src/07-multiprocessing/cpu_attempt/compute_it.py b/src/07-multiprocessing/cpu_attempt/compute_it.py index 415471e..e3d7900 100644 --- a/src/07-multiprocessing/cpu_attempt/compute_it.py +++ b/src/07-multiprocessing/cpu_attempt/compute_it.py @@ -10,7 +10,7 @@ def main(): do_math(num=30000000) dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") def do_math(start=0, num=10): diff --git a/src/07-multiprocessing/cpu_attempt/compute_multiprocessing.py b/src/07-multiprocessing/cpu_attempt/compute_multiprocessing.py index a31fccd..2272a60 100644 --- a/src/07-multiprocessing/cpu_attempt/compute_multiprocessing.py +++ b/src/07-multiprocessing/cpu_attempt/compute_multiprocessing.py @@ -8,7 +8,7 @@ def main(): t0 = datetime.datetime.now() - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") pool = multiprocessing.Pool() processor_count = multiprocessing.cpu_count() @@ -22,7 +22,7 @@ def main(): pool.join() dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") print("Our results: ") for t in tasks: print(t.get()) diff --git a/src/07-multiprocessing/cpu_attempt/compute_threaded.py b/src/07-multiprocessing/cpu_attempt/compute_threaded.py index 59d8dab..20e73f3 100644 --- a/src/07-multiprocessing/cpu_attempt/compute_threaded.py +++ b/src/07-multiprocessing/cpu_attempt/compute_threaded.py @@ -10,7 +10,7 @@ def main(): t0 = datetime.datetime.now() # do_math(num=30000000) - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") processor_count = multiprocessing.cpu_count() threads = [] @@ -25,7 +25,7 @@ def main(): [t.join() for t in threads] dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") def do_math(start=0, num=10): diff --git a/src/08-execution-pools/program.py b/src/08-execution-pools/program.py index 432e431..a24c473 100644 --- a/src/08-execution-pools/program.py +++ b/src/08-execution-pools/program.py @@ -29,7 +29,7 @@ def main(): print("Done", flush=True) for f in work: - print("{}".format(f.result()), flush=True) + print(f"{f.result()}", flush=True) def get_title(url: str) -> str: diff --git a/src/09-built-on-asyncio/the_trio/prod_asyncio.py b/src/09-built-on-asyncio/the_trio/prod_asyncio.py index 769316f..2d280a8 100644 --- a/src/09-built-on-asyncio/the_trio/prod_asyncio.py +++ b/src/09-built-on-asyncio/the_trio/prod_asyncio.py @@ -8,7 +8,9 @@ def main(): t0 = datetime.datetime.now() print(colorama.Fore.WHITE + "App started.", flush=True) - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() data = asyncio.Queue() task1 = loop.create_task(generate_data(20, data)) diff --git a/src/09-built-on-asyncio/the_unsync/nosync.py b/src/09-built-on-asyncio/the_unsync/nosync.py index 2b14dd1..f1ef2b4 100644 --- a/src/09-built-on-asyncio/the_unsync/nosync.py +++ b/src/09-built-on-asyncio/the_unsync/nosync.py @@ -20,7 +20,7 @@ def main(): wait_some() dt = datetime.datetime.now() - t0 - print("Synchronous version done in {:,.2f} seconds.".format(dt.total_seconds())) + print(f"Synchronous version done in {dt.total_seconds():,.2f} seconds.") def compute_some(): @@ -37,7 +37,7 @@ def download_some(): text = resp.text - print("Downloaded (more) {:,} characters.".format(len(text))) + print(f"Downloaded (more) {len(text):,} characters.") def download_some_more(): @@ -48,7 +48,7 @@ def download_some_more(): text = resp.text - print("Downloaded {:,} characters.".format(len(text))) + print(f"Downloaded {len(text):,} characters.") def wait_some(): diff --git a/src/09-built-on-asyncio/the_unsync/presync.py b/src/09-built-on-asyncio/the_unsync/presync.py index 9d2f42b..61577ad 100644 --- a/src/09-built-on-asyncio/the_unsync/presync.py +++ b/src/09-built-on-asyncio/the_unsync/presync.py @@ -9,7 +9,9 @@ def main(): t0 = datetime.datetime.now() - loop = asyncio.get_event_loop() + # Changed this from the video due to changes in Python 3.10: + # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop() + loop = asyncio.new_event_loop() tasks = [ loop.create_task(compute_some()), @@ -28,7 +30,7 @@ def main(): loop.run_until_complete(asyncio.gather(*tasks)) dt = datetime.datetime.now() - t0 - print("Synchronous version done in {:,.2f} seconds.".format(dt.total_seconds())) + print(f"Synchronous version done in {dt.total_seconds():,.2f} seconds.") async def compute_some(): @@ -46,7 +48,7 @@ async def download_some(): text = await resp.text() - print("Downloaded (more) {:,} characters.".format(len(text))) + print(f"Downloaded (more) {len(text):,} characters.") async def download_some_more(): @@ -57,7 +59,7 @@ async def download_some_more(): text = resp.text - print("Downloaded {:,} characters.".format(len(text))) + print(f"Downloaded {len(text):,} characters.") async def wait_some(): diff --git a/src/09-built-on-asyncio/the_unsync/thesync.py b/src/09-built-on-asyncio/the_unsync/thesync.py index a27c1d5..22d0594 100644 --- a/src/09-built-on-asyncio/the_unsync/thesync.py +++ b/src/09-built-on-asyncio/the_unsync/thesync.py @@ -27,7 +27,7 @@ def main(): [t.result() for t in tasks] dt = datetime.datetime.now() - t0 - print("Synchronous version done in {:,.2f} seconds.".format(dt.total_seconds())) + print(f"Synchronous version done in {dt.total_seconds():,.2f} seconds.") @unsync(cpu_bound=True) @@ -47,7 +47,7 @@ async def download_some(): text = await resp.text() - print("Downloaded (more) {:,} characters.".format(len(text))) + print(f"Downloaded (more) {len(text):,} characters.") @unsync() @@ -59,7 +59,7 @@ def download_some_more(): text = resp.text - print("Downloaded {:,} characters.".format(len(text))) + print(f"Downloaded {len(text):,} characters.") @unsync() diff --git a/src/10-async-web/acityscape_api/app.py b/src/10-async-web/acityscape_api/app.py index f72bf3a..8af2506 100644 --- a/src/10-async-web/acityscape_api/app.py +++ b/src/10-async-web/acityscape_api/app.py @@ -21,7 +21,7 @@ def configure_app(): services.sun_service.use_cached_data = data.get('use_cached_data') services.location_service.use_cached_data = data.get('use_cached_data') - print("Using cached data? {}".format(data.get('use_cached_data'))) + print(f"Using cached data? {data.get('use_cached_data')}") def run_web_app(): diff --git a/src/10-async-web/acityscape_api/views/city_api.py b/src/10-async-web/acityscape_api/views/city_api.py index 9162201..bfd72b6 100644 --- a/src/10-async-web/acityscape_api/views/city_api.py +++ b/src/10-async-web/acityscape_api/views/city_api.py @@ -1,7 +1,7 @@ import quart from services import weather_service, sun_service, location_service -blueprint = quart.blueprints.Blueprint(__name__, __name__) +blueprint = quart.blueprints.Blueprint("city_api", "city_api") @blueprint.route('/api/weather//', methods=['GET']) diff --git a/src/10-async-web/acityscape_api/views/home.py b/src/10-async-web/acityscape_api/views/home.py index 432d5de..9e995a0 100644 --- a/src/10-async-web/acityscape_api/views/home.py +++ b/src/10-async-web/acityscape_api/views/home.py @@ -1,6 +1,6 @@ import quart -blueprint = quart.blueprints.Blueprint(__name__, __name__) +blueprint = quart.blueprints.Blueprint("home", "home") @blueprint.route('/') diff --git a/src/10-async-web/cityscape_api/app.py b/src/10-async-web/cityscape_api/app.py index 40eb65a..0b534aa 100644 --- a/src/10-async-web/cityscape_api/app.py +++ b/src/10-async-web/cityscape_api/app.py @@ -21,7 +21,7 @@ def configure_app(): services.sun_service.use_cached_data = data.get('use_cached_data') services.location_service.use_cached_data = data.get('use_cached_data') - print("Using cached data? {}".format(data.get('use_cached_data'))) + print(f"Using cached data? {data.get('use_cached_data')}") def run_web_app(): diff --git a/src/10-async-web/cityscape_api/views/city_api.py b/src/10-async-web/cityscape_api/views/city_api.py index 8b238c0..9173c0c 100644 --- a/src/10-async-web/cityscape_api/views/city_api.py +++ b/src/10-async-web/cityscape_api/views/city_api.py @@ -1,7 +1,7 @@ import flask from services import weather_service, sun_service, location_service -blueprint = flask.blueprints.Blueprint(__name__, __name__) +blueprint = flask.blueprints.Blueprint("city_api", "city_api") @blueprint.route('/api/weather//', methods=['GET']) diff --git a/src/10-async-web/cityscape_api/views/home.py b/src/10-async-web/cityscape_api/views/home.py index cb725eb..a18b105 100644 --- a/src/10-async-web/cityscape_api/views/home.py +++ b/src/10-async-web/cityscape_api/views/home.py @@ -1,6 +1,6 @@ import flask -blueprint = flask.blueprints.Blueprint(__name__, __name__) +blueprint = flask.blueprints.Blueprint("home", "home") @blueprint.route('/') diff --git a/src/11-cython/perf/compute_cython.py b/src/11-cython/perf/compute_cython.py index 38d4040..22551d4 100644 --- a/src/11-cython/perf/compute_cython.py +++ b/src/11-cython/perf/compute_cython.py @@ -7,7 +7,7 @@ def main(): math_core.do_math(1) - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") processor_count = multiprocessing.cpu_count() threads = [] @@ -25,7 +25,7 @@ def main(): # math_core.do_math(num=300_000) dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec. (factor: {:,.2f}x)".format( + print("Done in {:,.4f} sec. (factor: {:,.2f}x)".format( dt.total_seconds(), 0.80 / dt.total_seconds()) ) diff --git a/src/11-cython/perf/compute_it.py b/src/11-cython/perf/compute_it.py index 93087f5..51ab1b4 100644 --- a/src/11-cython/perf/compute_it.py +++ b/src/11-cython/perf/compute_it.py @@ -10,7 +10,7 @@ def main(): do_math(num=3_000_000) dt = datetime.datetime.now() - t0 - print("Done in {:,.2f} sec.".format(dt.total_seconds())) + print(f"Done in {dt.total_seconds():,.2f} sec.") def do_math(start=0, num=10): diff --git a/src/11-cython/perf/compute_multiprocessing.py b/src/11-cython/perf/compute_multiprocessing.py index e41694f..490343d 100644 --- a/src/11-cython/perf/compute_multiprocessing.py +++ b/src/11-cython/perf/compute_multiprocessing.py @@ -8,7 +8,7 @@ def main(): t0 = datetime.datetime.now() - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") pool = multiprocessing.Pool() processor_count = multiprocessing.cpu_count() diff --git a/src/11-cython/perf/compute_threaded.py b/src/11-cython/perf/compute_threaded.py index 83006a2..be5ba46 100644 --- a/src/11-cython/perf/compute_threaded.py +++ b/src/11-cython/perf/compute_threaded.py @@ -10,7 +10,7 @@ def main(): t0 = datetime.datetime.now() # do_math(num=30000000) - print("Doing math on {:,} processors.".format(multiprocessing.cpu_count())) + print(f"Doing math on {multiprocessing.cpu_count():,} processors.") processor_count = multiprocessing.cpu_count() threads = []