This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.threading.Thread – a thread class

Here you see a very simple example how to create code which runs in another thread:

from c4d import threading

class MyThread(threading.Thread):

    def main(self):
        # put in your code here
        # which you want to run
        # in another thread
        pass


thr = MyThread()
thr.start(back=True)
#do some other operations here
thr.wait() #wait until the main method is done

Warning

See Threading information for important information about Threads.

class c4d.threading.Thread

// Methods to call

// Methods to override

Methods

Thread.start(back, priority=THREADPRIORITY_NORMAL, keeprunning=False)

Start the thread running.

Parameters:
  • back (bool) – Run the thread in background. True means asycnrhonous.
  • priority (int) –

    The thread priority:

    THREADPRIORITY_NORMAL Normal.
    THREADPRIORITY_ABOVE Above.
    THREADPRIORITY_BELOW Below.
  • keeprunning (bool) – Currently only supported on Windows. A thread that has this set to True is not suspended when it exits naturally (i.e. when it is not terminated by end() or CINEMA 4D itself). Instead it is sent to sleep. As Windows needs very long to start up a task this allows you to reuse the existing thread. For the programmer there is basically no difference, the thread has to be started with Thread. Internally however the thread won’t be terminated. This should only be used carefully and when absolutely necessary!
Thread.is_running()

Check if the thread is running.

Return type:bool
Returns:True if the thread is running, otherwise False
Thread.wait()
Wait until the thread has finished.
Thread.test_break()

Checks if the thread recieved a break command to stop processing.

Note

You can add more break conditions, such as if ESC has been pressed, in test_db_break().

Return type:bool
Returns:True if processing should be terminated, otherwise False.
Thread.test_db_break(self)

Override - Checks if the thread recieved a break command to stop processing.

Return type:bool
Returns:True if processing should be terminated, otherwise False.
Thread.main(self)

Override - In this method you can put in your code you want to execute in the threaded context.

Note

Remember that a scope might be done even the threaded code is still executed. In this situation you have to use wait() to wait until the code is finished or you should create an instance of your thread class into a scope which is longer alive than the code needs to run -

Table Of Contents

This Page