I'm creating a script that runs in a loop over and over again to check when a button is pressed.
When the button is pressed the script polls my website for a specific value. If the value is 1 then a light turns red. If the value is 2 then the light turns blue. It's pretty simplistic. The problem I'm running into is that the function that polls the website runs as a thread because I want the web checking part of the script to "peel off" and not halt my loop just in case the web request takes a while to occur due to network issues or any other issues.
Where I'm running into trouble is that if a user presses the button 10 times really quickly I don't want 10 threads to all of a sudden pop up. I want the button to try triggering the same thread so that if it's already running it just continues. If the thread has already stopped then it just starts up again. I don't quite understand the examples I'm seeing to get that part working.
All I have understood so far are the simplistic threads and from what I have read you can't actually control them once they have started.
This part works well but I just need to get over this hurdle to move on and I don't quite understand the tutorials I have been seeing out there.
When the button is pressed the script polls my website for a specific value. If the value is 1 then a light turns red. If the value is 2 then the light turns blue. It's pretty simplistic. The problem I'm running into is that the function that polls the website runs as a thread because I want the web checking part of the script to "peel off" and not halt my loop just in case the web request takes a while to occur due to network issues or any other issues.
Where I'm running into trouble is that if a user presses the button 10 times really quickly I don't want 10 threads to all of a sudden pop up. I want the button to try triggering the same thread so that if it's already running it just continues. If the thread has already stopped then it just starts up again. I don't quite understand the examples I'm seeing to get that part working.
All I have understood so far are the simplistic threads and from what I have read you can't actually control them once they have started.
Code:
import threading
import requests
function_test_function():
requests.get('http://mywebsite.com/returnvalue.php')
getLed_thread = threading.Thread(target=function_test_function)
getLed_thread.start()
This part works well but I just need to get over this hurdle to move on and I don't quite understand the tutorials I have been seeing out there.