-
- Posts: 15
- Joined: Wed Jun 03, 2015 4:13 pm
Do not wait for show message to finish
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
- Davespice
- Forum Moderator
- Posts: 1665
- Joined: Fri Oct 14, 2011 8:06 pm
- Location: The Netherlands
- Contact: Twitter
Re: Do not wait for show message to finish
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.
Example:
I hope this helps.
Example:
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)