Multiprocessing, Shared memory

artn3r

04-12-2009 20:58:24

Is there a way to share PO-objects between more Processes? One Process does the rendering,
the other the input or so. I tried to spawn a process in python using the multiprocessing package
and give it the ogre.root as parameter, but there comes an error wich says "pickling is disabled for .....)
-> he cannot serialize the object. Is there a way of shared memory in python? i just want to acces PO
objects from a few processes.

Thanks,
Christian

andy

05-12-2009 02:02:31

Isn't Ogre::root a singleton anyway ? So you should be able to do something like:
root = ogre.Root.getSingleton()
Regards
Andy

artn3r

05-12-2009 22:51:40

Thats working with threads, but not with processes. every process
has his own memory, so this does not work... i want to use multiprocessing
not multithreading, because multithreading in python isn't real multithreading
because of the GIL.

Thanks,
Christian

SirGolan

06-12-2009 16:59:14

You'd probably have to use something like Ampoule to send messages between the processes. The one process running Ogre would just receive the messages and relay them to Ogre.

artn3r

06-12-2009 19:34:57

I already did it with pyro - python remote objects. Its like RMI in java,
very usefull. thanks for your help!

Regards,
Christian

andy

07-12-2009 07:19:14

If you get a moment to write some demo code I'd be happy to add it to the svn as I think it would be of general interest...

Andy

artn3r

07-12-2009 22:34:35

Ok, first, download pyro and install it. i just tested it on windows.
if you are on linux, you can do multiprocessing with ogre, because
there is the POSH module (python object sharing) - not working in win32

http://pyro.sourceforge.net/
http://poshmodule.sourceforge.net/

Here is the code for pyro, just a quick example:

SERVER:

import Pyro.core
import Pyro.naming
import ogre.renderer.OGRE as ogre

class main(Pyro.core.ObjBase):

def __init__(self):

#This is a Pyro object, like 'extends Remote' in java
Pyro.core.ObjBase.__init__(self)

#init Ogre
self.root = ogre.Root("plugins.cfg","ogre.cfg")

def showConfig(self):
self.root.showConfigDialog()

def initWindow(self):
self.root.initialise(True, "ogrepyro-server")

def startRendering(self):
self.root.startRendering()

def getOgreRoot(self):
return self.root

#init pyro and run the pyro listening server
daemon=Pyro.core.Daemon()
uri=daemon.connect(main(),"app_main")
daemon.requestLoop()


CLIENT:

import Pyro.core

#get the object proxy from the server
app_main = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/app_main")

#you can call any funtions that are NOT returning ogre objects, because they are not serializable.
#maybe this can be enabled in the boost:python configuration, it's named pickling

#you can't do this:
#app_main.getOgreRoot()

app_main.showConfig()
app_main.initWindow()
app_main.startRendering()


Anyway, nobody thought about multiprocessing yet? I'm wondering because the threads in
python are **** because of the GIL =)
How do you implement multithreading, Andy?

Regards,
Christian