Hi! I am working @ a threading thingie right now and without Panda3D everything works as it should. Now that I want to create an thread that should take over the communication with the User (and thus requires Panda3D) I am stuck. After just copying and pasting some of the Panda3D-prog that worked, I don’t get any visible output at all.
Here is the header of Thread:
import direct.directbase.DirectStart
from direct.actor import Actor
from direct.showbase import DirectObject
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.task import Task
#from pandac import *
import cPickle
import threading, Queue, time, types
class Container:
def __init__(self):
self.items={}
def __getitem__(self, name='text'):
return self.items[name]
def __setitem__(self, name='text', content='text'):
self.items[name]=content
def addNewTextNode(self, name='text'):
self.items[name]=TextNode(name)
def addNewString(self, name='text'):
self.items[name]=str(name)
def addNewModel(self, name='text', model='model'):
self.items[name]=loader.loadModelCopy(model)
class ClientThread(threading.Thread, DirectObject):
def __init__(self, jobqueue, pipeline, name, individual={}):
threading.Thread.__init__(self)
DirectObject.__init__(self)
self.name=name
print "Thread",self.name,"is coming up..."
self.jobqueue=jobqueue
self.pipeline=pipeline
self.individual=individual
self.userName=None
self.password=None
self.secret=None
self.reference={}
self.referenceNr=0
self.supervisor=Container()
self.accept("escape",self.quit)
self.accept("end", self.screenie)
...
The next important thing for a thread is the run()-part:
def run(self):
print "starting loop!"
run()
But all I get is an empty Panda3D-screen with an error message like:
starting loop!
:express(warning): Adjusting global clock's real time by -3.36449 seconds.
Exception in thread Thread-9:Traceback (most recent call last):
File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap
self.run()
File "/home/bigfoot29/panda-workdir/threads/ClientThread.py", line 367, in run
run()
File "debtmp/usr/share/panda3d/direct/src/showbase/ShowBase.py", line 1603, in run
File "debtmp/usr/share/panda3d/direct/src/task/Task.py", line 781, in run
File "debtmp/usr/share/panda3d/direct/src/task/Task.py", line 720, in step
ValueError: signal only works in main thread
What I am wondering is: All processes I am calling are working. But he doesn’t like the loop as it seems… But I can’t run that one out of the main loop because a thread doesn’t have a main loop
Do I need to use the version without the “run()” command? Is there anything else I do wrong?
Regards, Bigfoot29
Edit: Trying it with while True: Task.step() instead of run() tells me:
starting loop!
Exception in thread Thread-9:Traceback (most recent call last):
File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap
self.run()
File "/home/bigfoot29/panda-workdir/threads/ClientThread.py", line 368, in run
Task.step()
AttributeError: 'module' object has no attribute 'step'
Seems as if I have some sort of import problems?
Edit2: My Fault: It has to be taskMgr.step() of course! However, then I get the same error like mentioned above