Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

cron job not terminating

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
jderickson
Posts: 4
Joined: 2023-05-24 13:29

cron job not terminating

#1 Post by jderickson »

Hello,
New poster here. I have run into a strange bug using Python 3.9.2 under Debian Bullseye. I have a very simple Python script that plays a sound file. I show the code below. This uses the pydub library but I have had the same result with playsound and pygame. I run the script as a cron job. The crontab entry is shown below. This is one minute just so I can see whether something is happening but it happens after longer intervals as well (2 min, 10 min, 30 min, etc).

The problem is that this seems to run fine for a while. Then the process table shows an accumulation of unterminated processes for the script. It takes a while for this to happen (runs normally for a while) then suddenly it starts piling up. Eventually memory is eaten up entirely and the system locks up. As I mentioned, this only seems to happen when I try to play a sound file, regardless of the library I use. When I tried it with pygame, I used the mixer.quit() and mixer.music.unload(), thinking that the file remained loaded, but this did not help

Any ideas here? I'm going to try:
a) more delay time afterward to allow the sound playing routine to close the file
b) try other sound playing libraries (I've tried playsound, pygame and pydub so far)
c) try reporting this in the Python user group, maybe a Python problem?

Thanks for any help.
Dave

Python code(xmitLMStonetest1.py)
import time
from pydub.playback import play
from pydub import AudioSegment

time.sleep(3)
sound = AudioSegment.from_wav('/home/user/Downloads/LMS-TEST-ONv3.wav')
play(sound)


time.sleep(1)



crontab entry
*/1 * * * * /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py

ps output after a while.
root 575 0.0 0.3 118920 25116 ? Ssl 09:01 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
root 1209 0.0 0.0 2480 572 ? Ss 10:22 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1210 0.1 0.2 39656 17452 ? SLl 10:22 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1215 0.0 0.0 2480 516 ? Ss 10:23 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1216 0.1 0.2 39656 17508 ? SLl 10:23 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1219 0.0 0.0 2480 516 ? Ss 10:24 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1220 0.1 0.2 39656 17428 ? SLl 10:24 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1223 0.0 0.0 2480 576 ? Ss 10:25 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1224 0.1 0.2 39656 17524 ? SLl 10:25 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1227 0.0 0.0 2480 576 ? Ss 10:26 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1228 0.1 0.2 39656 17456 ? SLl 10:26 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1231 0.0 0.0 2480 580 ? Ss 10:27 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1232 0.1 0.2 39656 17360 ? SLl 10:27 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1236 0.0 0.0 2480 576 ? Ss 10:28 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1237 0.1 0.2 39656 17448 ? SLl 10:28 0:02 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1240 0.0 0.0 2480 508 ? Ss 10:29 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1241 0.1 0.2 39656 17340 ? SLl 10:29 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1247 0.0 0.0 2480 508 ? Ss 10:30 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1248 0.1 0.2 39656 17364 ? SLl 10:30 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1251 0.0 0.0 2480 576 ? Ss 10:31 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1252 0.1 0.2 39656 19556 ? SLl 10:31 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1255 0.0 0.0 2480 508 ? Ss 10:32 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1256 0.1 0.2 39656 17452 ? SLl 10:32 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1261 0.0 0.0 2480 576 ? Ss 10:33 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1262 0.1 0.2 39656 17492 ? SLl 10:33 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1265 0.0 0.0 2480 572 ? Ss 10:34 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1266 0.1 0.2 39656 17404 ? SLl 10:34 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1270 0.0 0.0 2480 576 ? Ss 10:35 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1271 0.1 0.2 39656 17540 ? SLl 10:35 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1275 0.0 0.0 2480 580 ? Ss 10:36 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1276 0.1 0.2 39656 17444 ? SLl 10:36 0:01 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1279 0.0 0.0 2480 512 ? Ss 10:37 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1280 0.1 0.2 39656 17512 ? SLl 10:37 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1284 0.0 0.0 2480 512 ? Ss 10:38 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1285 0.1 0.2 39656 17492 ? SLl 10:38 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1288 0.0 0.0 2480 512 ? Ss 10:39 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1289 0.1 0.2 39656 17528 ? SLl 10:39 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1292 0.0 0.0 2480 576 ? Ss 10:40 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1293 0.1 0.2 39656 17524 ? SLl 10:40 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1296 0.0 0.0 2480 572 ? Ss 10:41 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1297 0.1 0.2 39656 17452 ? SLl 10:41 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1300 0.0 0.0 2480 516 ? Ss 10:42 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1301 0.1 0.2 39656 17468 ? SLl 10:42 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1306 0.0 0.0 2480 512 ? Ss 10:43 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1307 0.1 0.2 39656 17496 ? SLl 10:43 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1311 0.0 0.0 2480 576 ? Ss 10:44 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1312 0.1 0.2 39656 17332 ? SLl 10:44 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1315 0.0 0.0 2480 512 ? Ss 10:45 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1316 0.1 0.2 39656 17460 ? SLl 10:45 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1319 0.0 0.0 2480 516 ? Ss 10:46 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1320 0.1 0.2 39656 17460 ? SLl 10:46 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1323 0.0 0.0 2480 572 ? Ss 10:47 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1324 0.1 0.2 39656 17460 ? SLl 10:47 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1328 0.0 0.0 2480 512 ? Ss 10:48 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1329 0.2 0.2 39656 17416 ? SLl 10:48 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1332 0.0 0.0 2480 576 ? Ss 10:49 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1333 0.2 0.2 39656 17460 ? SLl 10:49 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1337 0.0 0.0 2480 584 ? Ss 10:50 0:00 /bin/sh -c /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1338 0.7 0.2 39656 17448 ? SLl 10:50 0:00 /usr/bin/python3 /home/user/Downloads/xmitLMStonetest1.py
root 1341 0.0 0.0 6372 640 ttyS0 S+ 10:50 0:00 grep python

User avatar
kent_dorfman766
Posts: 531
Joined: 2022-12-16 06:34
Location: socialist states of america
Has thanked: 57 times
Been thanked: 69 times

Re: cron job not terminating

#2 Post by kent_dorfman766 »

without reading the specifics of your problem, you can wrap the cron task under the "timeout" command so that it terminates if it runs longer than it is configured for. But that is a hack solution that should be a backup to solving the real problem.

And for what it's worth, utilizing the sound system thru cron probly isn't a good idea. mulitmedia really should be under direct UI control.

jderickson
Posts: 4
Joined: 2023-05-24 13:29

Re: cron job not terminating

#3 Post by jderickson »

I'm not sure what the limitation are of cron regarding audio. Seems like it should work the same any other system function. For example, I am writing to a serial port in this task. (I commented that out for testing, but it runs fine with the audio taken out). I think it must have something to do with either the file access or the actual audio output. I don't know if the file access is blocking, but it seems like it should be. The audio "play" calls are either blocking or there is a "playing" status that you can wait on. So it seems like everything should be done when the script exits. But apparently not. I guess I can put some diagnostic output in the script that would show where it stops.

jderickson
Posts: 4
Joined: 2023-05-24 13:29

Re: cron job not terminating

#4 Post by jderickson »

I am not going to use cron for this project. Apparently it's just problematic to use it to play audio. There have been many reports of problems with this. Since this is a dedicated system, I'm just going to have a job that runs in the background and uses a timer to do the audio calls. This seems to work fine.

User avatar
kent_dorfman766
Posts: 531
Joined: 2022-12-16 06:34
Location: socialist states of america
Has thanked: 57 times
Been thanked: 69 times

Re: cron job not terminating

#5 Post by kent_dorfman766 »

If you are using a gui desktop then it should have an autostart facility. write an audio control script and add it to your autostart. In that environment your standard file descriptors will be predictable and consistently under the control of the gui environment.

jderickson
Posts: 4
Joined: 2023-05-24 13:29

Re: cron job not terminating

#6 Post by jderickson »

Not using a GUI. This is an "embedded" special purpose application that does not need a GUI. I only log into it over a network or using a terminal connected to it.

Post Reply