Multiprocessing problem

I try to use multiprocessing for live data transmission and it pops up some weird bug.

Here is the reference:

Here is my main.py:

import subprocess
import sys

from direct.showbase.ShowBase import ShowBase
from multiprocessing import Process,Queue,Pipe
from mp1 import f

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        # quit when esc is pressed
        self.accept('escape', sys.exit)
        self.accept("f",self.hello)

        # base.disableMouse()

        self.jack = self.loader.loadModel("jack")
        self.jack.reparentTo(self.render)
        self.jack.setScale(2.0, 2.0, 2.0)
        self.jack.setPos(8, 50, 0)

    def hello(self):
        parent_conn, child_conn = Pipe()
        p = Process(target=f, args=(child_conn,))
        p.start()
        print(parent_conn.recv())  # prints "Hello"

app = MyApp()
app.run()

Here is mp1.py:

from multiprocessing import Process,Pipe

def f(child_conn):
    msg = "Hello"
    child_conn.send(msg)
    child_conn.close()

My expectation is when I press f, it will print “Hello” in the terminal.
However, when I press f, the programs will create a new panda3D window.
How can I solve this problem? Please let me know if you have a better solution in live data transmission

Thank you for reading this post.

Add:

if __name__ == '__main__':
   app = MyApp()
   app.run()

Your error tells you a strange bootstrapping message and google told me this. I can’t tell you I fully understand python things but either this is run too many times or too soon xD .

By using if __name__ == '__main__': you make sure only the main thread executes the app module…

More info about bootstrapping with multiprocessing can be found here:

1 Like