I have an app that runs in asyncio loop. I wish to start a thread which will execute a piece of blocking code:
def run(self)->bool:
self._running = True
while self._running:
#MOVE FORWORD / BACKWORDS
if kb.is_pressed('x'):
self.move_car("forward")
elif kb.is_pressed('w'):
self.move_car("backward")
return True
until I decide to stop it and manually set the self._running = False
by calling:
def stop(self):
self._running = False
These are both methods of a class controlling the whole operation of a raspberry pi robot-car I made.
I want this to run on a separate thread so that my main application can still listen to my input and stop the thread while the other thread is running in this while loop you can see above.
How can I achieve that?Note For sending the start and stop signal I use http
requests but this does not affect the core of my question.
source https://stackoverflow.com/questions/70866133/how-to-manually-start-and-stop-a-thread-running-blocking-code-within-a-python-as
Comments
Post a Comment