Background script only works when BGE player stops
I found out that you can make the script run in a loop by doing this:



Which allowed me to remove the thread and the infinite loop from my code:

print("---------------------------------------------")
print("Begin collection")

import serial

port = 'COM5'

def acc_data(ser):
    raw = ser.readline().decode("utf-8")
    data = raw.split(",")
    try:
        pitch = float(data[0])
        roll = float(data[1])
        print(str(pitch) + " " + str(roll))
    except:
        print("Only one value read")


try:
    acc_data(serial.Serial(port, 115200))
except:
    print("Unable to connect")


print("End collection")


This is what is printed in the console: