Hi, I’m working with a bunch of students for an university project. For our prototype it would be usefull to use python. And so we have two problems using the python/panda threadings.
First of all a little code example:
import time
#from threading import Thread, Event
from direct.stdpy.threading2 import Thread, Event
from pandac.PandaModules import Thread as PandaThread #@UnresolvedImport
class MyThread1(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
print "1"
time.sleep(20)
print "11"
class MyThread2(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
print "2"
time.sleep(0.5)
print "22"
def main():
#PandaThread.considerYield()
# test_event = Event()
print "Support panda threading: " , PandaThread.isThreadingSupported()
print "0"
thread1 = MyThread1()
thread2 = MyThread2()
print "00"
thread1.start()
print "000"
thread2.start()
print "0000"
time.sleep(4)
print "00000"
if __name__ == "__main__":
main()
And this is the console output:
Support panda threading: 1
0
00
1
11
000
2
22
0000
00000
This isn’t what i would expect. If I change the imports to “from threading import Thread” and use the python threadings, then it works fine.
Console output with python threading:
Support panda threading: 1
0
00
1
000
2
0000
22
11
00000
This is it, as it should be. But why not with the build-in panda threadings, which should be preferred? And if I change to “from direct.stdpy.threading import Thread”, the threads don’t start!
The second problem also considers the difference between the python and the panda threading:
If I use a panda thread, called A, besides the panda task (for rendering and so on), the frame rate dropps of 50% (from 60 to ~30).
Here an example of the run method of the thread A:
def run(self):
while not self.__stopped:
PandaThread.considerYield()
print time.clock()
time.sleep(self.__dtime)
The usage of the python theads solves the frame rate problem. But where is the problem in the panda threading module?
Thanks