2 posts • Page 1 of 1
I have a program that relies on the joystick always being active, and if I call the function show_message(), it stops the system till the text has finished scrolling. Is there a way to stop it doing this and do it in the background? Thanks
- Forum Moderator
- Posts: 1665
- Joined: Fri Oct 14, 2011 8:06 pm
- Location: The Netherlands
- Contact: Twitter
Hi there, I remember you from last time! You want to look into the Python threading module. This allows you to kick off a function and return immediately to go onto the next line of code leaving the function to run in the background.
I hope this helps.
Code: Select all
import time import threading as th from sense_hat import SenseHat sense = SenseHat() def message_shower(message): global sense sense.show_message(message) def show_message_background(message): th.Thread(target=message_shower, args=(message,)).start() show_message_background("my name is Dave") while True: print("sleeping...") time.sleep(1)