On Wednesday, 17 February 2021 13:32:19 GMT Terry Coles wrote:
> In any case, the Bells Pi code uses the same approach, so how come that
> works and the Music code doesn't?

I think I've sussed this. :-)  At least I think I know what is going wrong.

In order to respond to commands coming in from the Webserver, I have a 
function called check_webserver_commands().  This periodically checks for data 
on the socket, parses it and calls the appropriate function; in this case 
restartmp3() (which calls mp3_player_start() ).  To service this function, I 
added a line to apscheduler:

    sched.add_job(check_webserver_commands, 'interval', seconds=1, 

The problem with this is that when the calling function takes a long time to 
return, I get an error (too many instances), so I added a line to the 
beginning of check_webserver_commands():

    sched.pause_job(job_id='check_webserver_commands') # Suspend until current 
job is complete

and one at the end:

    sched.resume_job(job_id='check_webserver_commands')# Restart checking for 

The problem is that the mp3_player_start() function doesn't return until the 

        mp3_wait = mp3_player.wait()

 has completed (and never if the loop is active), so the sched.resume job 
never gets run.

I used apscheduler to ensure that the check_webserver_commands() function 
would get called frequently, but without locking the program up during the 
intervals between each check, but it would seem that it doesn't successfully 
interrupt the mp3_player.wait() method.

I need that method to tell me when the loop is completed, so can anyone 
suggest a better way to poll the check_webserver_commands() function or to 
make the mp3_player.wait() method more interruptible?

Of course I may be wrong on my hypothesis, but when I put the sched.resume() 
method just before the call to restartmp3() the rest of the commands from the 
Webserver were recognised and serviced.


                Terry Coles

  Next meeting: Online, Jitsi, Tuesday, 2021-03-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to