Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Parallel programming: Synchronizing processes

$
0
0

I have a program which has a lot of music decks (deck 1, deck 2, music_clip_deck, speackers_deck, ip_call_1, ip_call_2, ip_call_3). Each deck works in a seperate process. The chunk time I use to crop the mp3 files/retransmitions stream/voice from microphone/voice from aiortc-pyav is 125msec. After that I fill some queues (one for each seperate process) and I send the final queue to the final thread for the final audio processing before hearing and transmitted to clients.

How can I synchronize all the process together, so one while run time of each process takes exactly 125 msec?

Here is one figure for help:

enter image description here

This approach may not help at all:

class Deck_1_Proc(Process):.........    def run(self):        while(True):            t1 = time.time()            ...            ...            ...            t2 = time.time()            if t2 - t1 < 0.125:                time.sleep(0.125 - (t2 - t1))

Maybe a better approach should be use something like javascript setInterval with time parameter: 125msec

from threading import Event, Threaddef call_repeatedly(interval, func, *args):    stopped = Event()    def loop():        while not stopped.wait(interval): # the first call is in `interval` secs            func(*args)    Thread(target=loop).start()        return stopped.set#call:cancel_future_calls = call_repeatedly(0.125, run)#stopping to app termination:cancel_future_calls()

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>