From 034a29cecb3461643592dd8b74348aa99568bd6c Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Tue, 9 Jun 2026 02:02:28 +1000 Subject: [PATCH] sync --- src/threading_test.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/threading_test.py diff --git a/src/threading_test.py b/src/threading_test.py new file mode 100644 index 0000000..e822ecd --- /dev/null +++ b/src/threading_test.py @@ -0,0 +1,48 @@ +import threading +import time + +TICK_RATE = 7.8 / 1000 # Ticks per second + +AMOUNT = 0 +AMOUNT_MOD = 1 + + +def task(): + print("Thread running") + + +def print_amount(length=1): + print(length) + global AMOUNT + print(AMOUNT) + while True: + print(AMOUNT) + time.sleep(length) + + +def do_tick(): + global AMOUNT + global AMOUNT_MOD + AMOUNT += AMOUNT_MOD + # print("tick!") + + +def run(): + iteration = 0 + while True: # One tick + start_time = time.time() + do_tick() + end_time = time.time() + + time.sleep(TICK_RATE - (end_time - start_time)) + iteration += 1 + + +thread = threading.Thread(target=run) +thread2 = threading.Thread(target=print_amount, kwargs={"length": 1}) +print(f"Thread created: {thread.name}") + +thread.start() +thread2.start() + +# thread.join()