If I'm understanding you correctly, you want to execute some code outside of the loop while the songs are playing. As the playing itself already appears to happen in the background, the most simple approach would be to call some other routine in your program every time you get around to calling sleep at the end of the loop, and when that routine returns, just sleep for the remaining time only (i.e. song length minus time the routine took). That would mean your other code executes synchronously with the loop iterations, so a single call of the routine may not take more time than the length of the current song allows. — In other words, make that while loop the main loop of your program and arrange the other code around it.
If you need asynchronous execution, you could use threads or fork a separate process. Which technique to use depends on a number of factors, for example how you want to share data. The latter is somewhat simpler with threads, because different processes (as created with fork) would require interprocess communication (IPC), such as pipes, sockets and signals, to explicitly exchange information.
In reply to Re: Looping in the background of your main program
by almut
in thread Looping in the background of your main program
by Baphi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |