c4d.threading.C4DThread

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

import c4d
from c4d.threading import C4DThread
class UserThread(C4DThread):
  def Main(self):
    # 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 informations about threads.

Definition

class c4d.threading. C4DThread

Methods to Call

Methods to Override

Methods

C4DThread. Get ( )

Get the BaseThread for this thread.

Return type: c4d.threading.BaseThread
Returns: The BaseThread of this thread.
C4DThread. Start ( mode=THREADMODE_ASYNC , priority=THREADPRIORITY_NORMAL )

Start the thread running.

Parameters:
  • mode ( int ) –

    Thread mode:

    THREADMODE_DEPRECATED_SYNCHRONOUS Synchronous thread. Deprecated.
    THREADMODE_ASYNC Asynchronous thread.
  • priority ( int ) –

    Thread priority:

    THREADPRIORITY_NORMAL Normal.
    THREADPRIORITY_ABOVE Above.
    THREADPRIORITY_BELOW Below.
    THREADPRIORITY_LOWEST Lowest.
Return type:

bool

Returns:

True if the thread was started, otherwise False .

C4DThread. End ( 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. IsRunning ( )

Checks if the thread is running.

Return type: bool
Returns: True if the thread is running, otherwise False .
C4DThread. Wait ( 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 occured.
C4DThread. TestBreak ( )

Checks if the thread recieved 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. 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 .

Table Of Contents