This commit is contained in:
Benjamyn Love 2026-06-09 02:02:28 +10:00
parent d655c4d219
commit 034a29cecb

48
src/threading_test.py Normal file
View File

@ -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()