0

Hey so I have been making this script to download audio ,then split the audio, then run 4 similar functions in parallel. It keeps running the first two scripts fine then runs the entire script 4 times over.

from login import account_login
from soundsplitter import sound_splitter
from main import get_sound
from tkinter import *
from functools import partial
start_up = True

if start_up:
    get_sound()
    print('Sounds have been downloaded')
    sound_splitter()
    print('Sounds have been split')
    start_up = False


if not start_up:
    from frequencysplitter import frequency_splitter_Short_30CUT, frequency_splitter_Short_60CUT, \
        frequency_splitter_Medium_30CUT, frequency_splitter_Medium_60CUT
    import multiprocessing

    p1 = multiprocessing.Process(target=frequency_splitter_Short_30CUT)
    p2 = multiprocessing.Process(target=frequency_splitter_Short_60CUT)
    p3 = multiprocessing.Process(target=frequency_splitter_Medium_30CUT)
    p4 = multiprocessing.Process(target=frequency_splitter_Medium_60CUT)

    p1.start()
    p2.start()
    p3.start()
    p4.start()

    p1.join()
    p2.join()
    p3.join()
    p4.join()

How can I make it so that the get_sound() and sound_splitter() run first and then the multiprocessing kicks up without it running the entire code again

  • Does this answer your question? [Compulsory usage of if \_\_name\_\_=="\_\_main\_\_" in windows while using multiprocessing](https://stackoverflow.com/questions/20360686/compulsory-usage-of-if-name-main-in-windows-while-using-multiprocessi) – Ahmed AEK Nov 22 '22 at 18:25
  • https://stackoverflow.com/questions/20222534/python-multiprocessing-on-windows-if-name-main?noredirect=1&lq=1 – Ahmed AEK Nov 22 '22 at 18:26
  • so do I wrap both items in two separate __main__ ? @AhmedAEK – Elliott Mitch Nov 22 '22 at 18:29
  • what does importing `frequencysplitter` do that makes it necessary to wrap it in an if condition instead of putting it in the first few lines like you should ? all imports should be in the first few lines before any "logic" or "definitions"..... like why can't you put all your imports at the top ? – Ahmed AEK Nov 22 '22 at 18:37
  • the most straight forward way is to wrap all your "logic" in a `main` function and just do `if __name__ == "__main__": main()` , but all imports should be done before the function definition ... so i am asking if you can move all your imports to the very top. – Ahmed AEK Nov 22 '22 at 18:42

0 Answers0