THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/02/2012 at 10:39, xxxxxxxx wrote:
I'm trying to figure out how to use threading for scripts. And having a hard time of it.
Here's my list of what I want to accomplish with threading:
1. Create a thread to run some code in it that is taxing(looping) on my system
2. Have the ability to stop the process with the ESC key by the user
3. Have this all done Asynchronously(Not sure if this is possible with scripts)
Here's a code example to get things started:
import c4d from c4d import threading class MyThread(threading.C4DThread) : #Something to run and tax the system def myThreadedFunction(self) : for i in xrange(0,2000) : mt = c4d.threading.GeIsMainThread() #Test if the main thread is running print mt tId = c4d.threading.GeGetCurrentThreadId()#Get the threads ID print tId c4d.StatusSetText(i) c4d.StatusClear() def main() : thread = MyThread() thread.Start(c4d.THREADMODE_ASYNC, c4d.THREADPRIORITY_NORMAL) thread.myThreadedFunction() if __name__=='__main__': main()
This example has some problems.
-It returns "true" meaning that it's running in the main thread...Which is bad. I want another thread to be running instead.
-And I don't know how to add the ESC key to stop it from running.