-1

I'm trying to make a GUI application that incorporates both image and audio processing simultaneously using the multiprocessing library. However the same code when tested on a Mac OS X does not seem to work, unless I remove the import tkinter statement

import pyaudio
# The import statement below is causing the problem
import tkinter as tki
import multiprocessing
import threading

def do_task():
    p = pyaudio.PyAudio()
    print("Task complete")

if __name__ == '__main__':
    p = multiprocessing.Process(target=do_task, args=())
    p.start()
    # Code works when import statement is placed here
    # import tkinter as tki
    p.join()

The above code prints Task complete on Windows and also prints Task complete when the import statement is shifted, which is not a good solution as I'll need to start the multiprocessing after I initialize the UI.

Is there any workaround to this problem?

1 Answers1

0

It would be nice if we knew what exactly the Error is, so if you could copy it in it would be nice. ^^ Anyways I don't have good experiences with multiprocessing.Process either so I use threading.Thread instead. Therefor I define a new class with Thread as metaclass and define whatever the running function should be as run. e.g.:

from threading import Thread

class Audio(Thread):
    def __init__(self,...):
        Thread.__init__(self)
        #...
    def run(self):
        #audio stuff

class GUI(Thread):
    def __init__(self,...):
        Thread.__init__(self)
        #...
    def run(self):
        #GUI stuff
a,g=Audio(),GUI()
a.start(),g.start()

I don't know if that really helps but I hope so. :D

Nummer_42O
  • 334
  • 2
  • 16