c4d.threading.C4DThread

class c4d.threading.C4DThread

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

import c4d

class UserThread(c4d.threading.C4DThread):

    def Main():
        # Put in your code here
        # which you want to run
        # in another thread
        pass


thread = UserThread()
thread.Start()
# Do some other operations here
thread.Wait(True) # Wait until the main method is done

Warning

Ensure that every thread created by C4DThread is closed by the user on exit.
PluginMessage() can be used for that purpose, intercepting C4DPL_ENDACTIVITY message.

See also

Threading Information for important information about threads.

Methods Signatures

Methods to Override

C4DThread.Main(self)

Override with your thread main code.

C4DThread.TestDBreak(self)

Override this to add user breaks such as pressing ESC. This function is called by TestBreak().

Methods to Call

C4DThread.End(self[, wait])

End the thread.

C4DThread.Get(self)

Get the BaseThread for this thread.

C4DThread.IsRunning(self)

Checks if the thread is running.

C4DThread.Start(self[, mode, priority])

Start the thread running.

C4DThread.TestBreak(self)

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

C4DThread.Wait(self, checkevents)

Waits until the thread has finished.

Methods Documentation

C4DThread.Main(self)

Override with your thread main code.

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.
C4DThread.TestDBreak(self)

Override this to add user breaks such as pressing ESC. This function is called by TestBreak().

Return type

bool

Returns

True if processing should be terminated, otherwise False.

C4DThread.End(self, wait=True)

End the thread.

Note

If the thread does not check for TestBreak() then this function will not return and you will get a deadlock.

Parameters

wait (bool) – This parameter determines if thread termination is synchronous or asynchronous. If True the function will not return until the thread is finished. If False the function returns immediately although the thread will still run until it is finished.

C4DThread.Get(self)

Get the BaseThread for this thread.

Return type

c4d.threading.BaseThread

Returns

The BaseThread of this thread.

C4DThread.IsRunning(self)

Checks if the thread is running.

Return type

bool

Returns

True if the thread is running, otherwise False.

C4DThread.Start(self, mode=THREADMODE_ASYNC, priority=THREADPRIORITYEX_NORMAL)

Start the thread running.

Parameters
  • mode (int) –

    Thread mode:

    THREADMODE_DEPRECATED_SYNCHRONOUS

    Synchronous thread. Deprecated.

    THREADMODE_ASYNC

    Asynchronous thread.

    THREADMODE_PRIVATE_OPENGL

    New in version R18: Private

  • priority (int) –

    Thread priority:

    Symbol ID

    Description

    THREADPRIORITYEX_NORMAL

    Normal.

    THREADPRIORITYEX_ABOVE

    Above.

    THREADPRIORITYEX_BELOW

    Below.

    THREADPRIORITYEX_LOWEST

    Lowest.

Return type

bool

Returns

True if the thread was started, otherwise False.

C4DThread.TestBreak(self)
Checks if the thread received a break command to stop processing.
Normally this is only True when Cinema 4D is closing, or when End() has been called.

Note

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

Return type

bool

Returns

True if processing should be terminated, otherwise False.

C4DThread.Wait(self, checkevents)

Waits until the thread has finished.

Parameters

checkevents (bool) – If False then wait until the thread has finished. If True then additionally return if a Cinema 4D event occurred.