A bit of background: I have a Raspberry Pi 3b running Raspbian(Debian) 9.11. This original Pi runs a Python 3 script that captures text input from a handheld scanner and sends it into a MySQL database, and then plays a wav file so the employees scanning know it was successful. I daemonized this process so it was easier to restart (sometimes the scanners lose sync with their USB dongles). The main line in the daemon file is this
ExecStart=/usr/bin/python3 /home/pi/Desktop/scanner.py
I had to change the process slightly for a new instance I was asked to create, so I loaded Raspbian 10.4 (latest) onto another Pi 3b and moved everything over with only the slight tweak that it now inserts to a local Maria DB (MySQL basically). Daemon runs just fine... except that no audio plays (but the DB insert still happens). What's really weird is when I load it in Thonny, it plays the file just fine. There's nothing in the syslog indicating Python or Pygame are generating any errors.
The relevant code here (abbreviated) is
import pygame.mixer
# sets up sound
pygame.mixer.init()
goodscan = pygame.mixer.Sound('/home/pi/Desktop/goodscan.wav')
duplicatescan = pygame.mixer.Sound('/home/pi/Desktop/duplicateScan.wav')
badscan = pygame.mixer.Sound('/home/pi/Desktop/badScan.wav')
#function that the USB listener calls
def scan(scanner):
#some scanner processing codes here
if prevScan == x:
duplicatescan.play()
print("Duplicate Scan")
continue;
else:
splits = x.split('-')
if(len(splits) < 3):
print("No prefix provided")
#write to error log
badscan.play();
continue;
prefix = splits[0][0] + splits[0][1]
po = splits[1] + '-' + splits[2]
scanner_number = splits[0][2] + splits[0][3]
polist.extend([po, prefixes[prefix], scanner_number])
goodscan.play()
#DB insert (this always works)
scans = {
"timestamp": time_str,
"ponum": x,
"status": polist[1],
"scanner": polist[2]
}
statusUpdate.databaseUpdate(polist)
How can I debug why this isn't working in daemon mode?