Top  | Previous | Next

system.util.invokeAsynchronous

Description

This is an advanced scripting function. Invokes (calls) the given Python function on a different thread. This means that calls to invokeAsynchronous will return immediately, and then the given function will start executing asynchronously on a different thread. This is useful for long-running data intensive functions, where running them synchronously (in the GUI thread) would make the GUI non-responsive for an unacceptable amount of time.

 

sign_warning WARNING: Under no circumstances should you ever do anything in the function that is invoked asynchronously that interacts with the GUI. This means things like window navigation, setting and getting component properties, showing error/message popups, etc. If you need to do something with the GUI in this function, this must be achieved through a call to system.util.invokeLater.

Syntax

system.util.invokeAsynchronous(function)

Parameters

PyObject function - A Python function object that will get invoked with no arguments in a separate thread.

Returns

nothing

Scope

All

Examples

# This code would do some data-intensive processing, and then call

# back to the GUI to let it know that it is finished.

# We use default function parameters to pass the root container into these

# functions. (See a Python reference if you don't understand this)

 

def longProcess(rootContainer = event.source.parent):

   import system

   # Do something here with the database that takes a long time

   results = ...( something )

   # Now we'll send our results back to the UI

   def sendBack(results = results, rootContainer = rootContainer):

      rootContainer.resultsProperty = results

   system.util.invokeLater(sendBack)

   

system.util.invokeAsynchronous(longProcess)