[Python] Python: Struggling with Multiprocessing

Discussão em 'Python' iniciado por Stack, Março 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently working on a loudness meter with a raspberry pi and python. The raspberry is connected to a sensor for loudness metering and a common USB microphone. Whenever the value of the loudness meter exceeds a certain threshold, the microphone shall start a 10s recording, so that the source of the noise gets documented.

    Everytime the microphone is recording something, the readout of values from the loudness meter should continue in parallel. Because of that, I thought of using the multiprocessing module. Unfortunately, this is new stuff for me and it's not working so far. Although every function is working on it's own, I haven't managed to make them work at the same time. Because of that, I would appreciate, if you could support me here.

    In a short version, my code looks like this:

    import multiprocessing

    def reading_values_from_loudness_meter():
    (...)
    # This function checks the values continuously and appends them to a list, if they exceed the threshold.

    def recording_audio():
    (...)
    # Checks, if there are values in the list and starts recording, when the list is not empty. Whenever a recording is triggered, the list gets cleared. Whenever the recording ends, the list is checked again for values.

    u = 1
    p1 = multiprocessing.Process(target=reading_values_from_loudness_meter)
    p2 = multiprocessing.Process(target=recording_audio)

    p1.start()

    while u == 1:
    p2.start()
    p2.join()

    Continue reading...

Compartilhe esta Página