-2

I am trying to create a reaction game that will penalize users for reacting too quickly. I need to be able to run the program and while the program is running, checking for users that input too quickly. The while statement will have to go endlessly until the user is supposed to react. So basically I just need to know how to run a while statement in the background without interfering with program's operations. Also note, I am not using raw_input because I have a hardware button. So if the hardware button is 1, then print 'YOU WENT TOO EARLY' or something. But I can't just have the if statement go once, it has to go in a while 1:. Sorry if this is a stupid question, but I am at a lost on how to do such a thing. Thanks in advance!!

user3709398
  • 85
  • 1
  • 5

1 Answers1

1

Have you heard about Python's GIL? The Global Interpreter Lock? By default you can't just run things in parallel...

However, I think your main problem is your design here, because this can be solved by just running your reaction function recursively, right? Start your function with a time 0.0, and just check via an "if statement" if the time interval (user input - start time) was too small, and if so, do recursion using the already elapsed time.

But if you are really want to run things in parallel, although I think it doesn't make sense for this application, you might want to check out the multiprocessing module, I have a short tutorial here if it helps.