Hi, I am coding a server using panda3d and I am facing one problem when dealing with the tasks/threads.
Right now I have the program divided in two parts, one that is an infinite loop that checks if there is a new connection to accept (if there is, it accepts it) and a then sleeps for 0.05 seconds.
The other part is triggered when enough accepted connections are reached, at this point the program should spawn a new thread to handle a hosted game. The old thread keeps accepting connections.
I am currently using this infinite loop and sleep code because if I use tasks in the normal way the program will consume all my CPU, even if it is doing absolutely nothing.
My problem is in the new thread spawn part, I tried using actual threads, but this causes the program to crash when it tries to load the actors, here is the error message:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/share/panda3d/direct/stdpy/threading2.py", line 472, in __bootstrap
self.run()
File "/usr/share/panda3d/direct/stdpy/threading2.py", line 452, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/fernando/Documents/projects/PythonArenaServer/instance.py", line 69, in manageHostedGame
self.createAndSendLoginAndPlayerInfo()
File "/home/fernando/Documents/projects/PythonArenaServer/instance.py", line 100, in createAndSendLoginAndPlayerInfo
loadedPlayer = Player(id, x, y, z, scale, playerClass, connection, playerCollisionTravesser, side, maxHp, name)
File "/home/fernando/Documents/projects/Arena/worldCharacters.py", line 137, in __init__
annimationDict
File "/usr/share/panda3d/direct/actor/Actor.py", line 277, in __init__
self.loadModel(models, copy = copy, okMissing = okMissing)
File "/usr/share/panda3d/direct/actor/Actor.py", line 1889, in loadModel
model = loader.loadModel(modelPath, loaderOptions = loaderOptions, okMissing = okMissing)
File "/usr/share/panda3d/direct/showbase/Loader.py", line 159, in loadModel
node = self.loader.loadSync(Filename(modelPath), loaderOptions)
AttributeError: Loader instance has no attribute 'loader'
I also tried using task chains, I used this code:
taskMgr.setupTaskChain('IstanceChain'+str(taskChainId), numThreads = 1, tickClock = False)
taskMgr.add(
self.manageHostedGame,
'Hosted game'+str(taskChainId),
taskChain = 'IstanceChain'+str(taskChainId)
)
The task chain code seems to be ignored, as the program executes it, but the function I added in the taskMgr.add is not executed at all (I tried placing a print in the first line of the function and it is never called).
Some extra info:
I am using ubuntu 10.04 64 bits and panda 7.2, the program is windowless (since it is a server), but it does load models so that it can process collisions. Loading models works fine with threading but loading actors doesn’t.
Any help is very well appreciated.