Python code not continuing execution after thread started

后端 未结 1 1412
天命终不由人
天命终不由人 2021-01-24 02:59

I am writing a threaded Python script for the first time and running into some trouble. The general idea is that a Raspberry Pi receives data from a Bluetooth connection, this

1条回答
  •  抹茶落季
    2021-01-24 03:43

    You are using the threading module wrong. This line

    threading.Thread(target=start_laps(int(data["delay"]), ast.literal_eval(data["lap_times"])))
    

    executes the function start_laps, which obviously blocks the program. What you want is the following:

    threading.Thread(target=start_laps, args=(int(data["delay"]), ast.literal_eval(data["lap_times"])))
    

    This executes the function in the created Thread with the given args

    0 讨论(0)
提交回复
热议问题