Multiple independent Panda3D applications in parallel

Hello to all black’n’white bears,
I’d like to embed multiple Panda3D windows in a wxPython application. The embedding is not a problem, but creating multiple windows and having an independent task manager for each is.
Panda is very monolithic. Intentionally, there is only one instance of ShowBase, one global task manager and one main loop.
That said, every single window Panda renders to will run at the same framerate (one laggy makes all laggy) and errors encountered in one application will crash everything.

What I’m looking for is having multiple independent applications running in parallel and started by the same python script, but both running independent - best all asynchronously in separate threads.

Any ideas on how to archieve that?

I would try the multiprocessing module. Run a separate python interperter + Panda3d per process. And run wxpython in the main process.

It’s very easy to communicate between process using the multi-process Queue. Then the problem would be reduced down to how to get control of the child process’s window using the parent process’ wxpython.

Or I would just run two copies of wxpython as well. That would probably be easier.

import os
import time
from multiprocessing import Process
import math

def sleeper(name, seconds):
	import PandaHeader
	from pandac.PandaModules import Point2, Point3, Plane, Vec3, Vec4, VBase3, VBase4 
	print 'child: starting child process with id: ', os.getpid()
	#print 'parent process:', os.getppid()
	print 'child: sleeping for %s ' % seconds
	a = Vec3(0,0,0)

if __name__ == '__main__':
	osid = os.getpid()
	print "in parent process (id %s)" % os.getpid()
	p = Process(target=sleeper, args=('bob', 5))
	import PandaHeader
	from pandac import *

	print "I got main"
	print "in parent process after child process start"
	t = loader.loadModel('smiley')
	t.reparentTo( render )


The import PandaHeader is my own wrapped version of directstart… The only trick is to import/start panda, wxpython only after the child process has been created.

Sorry for the late reply.
Your tip was awesome and worked like a charm.

For the record, here’s the result: … highlight=

It’s about wx and panda, but you can generally also run multiple Panda instances with similar code.

Sound great! I’m happy it worked out for you.