Howabout;
import threading
import soya
class soyathread:
def __init__(self):
soya.init()
soya.path.append(os.path.dirname(sys.argv[0]))
self.world = soya.World()
""" etc whatever you wish to do.. set self.cam and such"""
def run(self):
soya.set_root_widget(self.cam)
self.idler = soya.Idler(self.world)
self.idler.idle()
class mainthread(threading.Thread):
def __init__(self,soyaref):
threading.Thread.__init__(self)
self.soyaref = soyaref
def run(self):
time.sleep(1)
while 1:
IO = raw_input('\r\nType 'stop' to stop soya>>> ')
if IO == 'stop': self.soyaref.idler.stop() # soya idler quits.
if __name__ == '__main__':
soyathread = soyathread()
mainthread = mainthread(soyathread)
mainthread.start()
soyathread.run()
There are even better ways to do this so you can stop rendering to
save cpu (and so you can resume it later). Can't remember how I did
years back. But I assume this is enough for you since you just want to
stop the thread.
On 9/10/08, Bastian Venthur <[EMAIL PROTECTED]> wrote:
> Hi
>
> assuming my application runs in two threads: one for the soya stuff and
> the other to steer the first thread -- how to do I stop the
> soya-mainloop running in the first thread from the second thread?
>
> I've currently two solutions:
>
> Solution 1:
>
> Thread2 sets a shared variable which is checked in Thread1 (eg in a
> begin_round)
>
> If Thread1 detects, that this variable is set, it calls
> soya.MAIN_LOOP.stop()
>
> Problem: It takes a while (sometimes minutes) until the main-loop quits.
> I suppose the problem is, that Thread1 which runs the mainloop eats up
> all the CPU cycles and it just takes some random amount of time until
> Thread2 can actually set the variable.
>
>
> Solution 2:
>
> Instead of running the mainloop in Thread1, I just call the update
> method repeatedly:
>
> while not stopping:
> time.sleep(0.025) # 40 FPS
> my_mainloop.upate()
>
> the sleep call assures that Thread2 doesn't starve. Setting "stopping"
> in Thread2 has immediate effect on Thread1.
>
> Problem: due the sleep call (no matter how small the value is -- even 0)
> causes the rendered output to judder -- it looks like 4 FPS not 40.
>
>
> What would be your solution to stop the soya-thread from a second one,
> without losing performance in the rendering?
>
>
> Cheers,
>
> Bastian
>
>
> --
> Bastian Venthur http://venthur.de
> Debian Developer venthur at debian org
>
>
>
> _______________________________________________
> Soya-user mailing list
> [email protected]
> https://mail.gna.org/listinfo/soya-user
>
_______________________________________________
Soya-user mailing list
[email protected]
https://mail.gna.org/listinfo/soya-user