Pausing one thread from within another thread

I’m improving a music playing script I’ve written; I want to add a
feature that automatically pauses the music if I wander off by detecting
the bluetooth on my phone. The main thread deals with the UI while there
is a thread running to play whatever is on the playlist and another
thread to deal with the auto-pausing.

At the moment I’m pausing the music by using “system(‘killall -STOP
mpg321’)”, this is quite crude and can get confused by other instances
of mpg321. While Thread.stop will pause a thread from within, I cannot
work out a way to pause a thread from another thread. Is this possible,
or is there a good reason why this has been omitted?

Thanks,
Mike

If mpg123 is what’s actually playing the music, then that’s what you
need
to stop, not the thread that’s shelling out to it.

You might look at Process.spawn, which can be used to obtain mpg123’s
PID.
You can then use Process.kill to send it signals, rather than shelling
out
to killall.

Thanks for that; it turns out that IO.popen worked slightly better but
it would have taken me a long time to get it working without your
pointer. In case you’re interested as to what I was doing I’ve written
it up here:

Thanks a lot,
Mike