model_thread

class camelot.view.model_thread.AbstractModelThread(setup_thread=<function setup_model at 0x5754f50>)[source]

Abstract implementation of a model thread class Thread in which the model runs, all requests to the model should be posted to the the model thread.

This class ensures the gui thread doesn’t block when the model needs time to complete tasks by providing asynchronous communication between the model thread and the gui thread

The Model thread class provides a number of signals :

thread_busy_signal

indicates if the model thread is working in the background

setup_exception_signal

this signal is emitted when there was an exception setting up the model thread, eg no connection to the database could be made. this exception is mostly fatal for the application.

busy()[source]

Return True or False indicating wether either the model or the gui thread is doing something

post(request, response=None, exception=None, args=())[source]

Post a request to the model thread, request should be a function that takes no arguments. The request function will be called within the model thread. When the request is finished, on first occasion, the response function will be called within the gui thread. The response function takes as arguments, the results of the request function.

Parameters:
  • request – function to be called within the model thread
  • response – a slot that will be called with the result of the

request function :param exception: a slot that will be called in case request throws an exception :param args: arguments with which the request function will be called

stop()[source]

Stop the model thread from accepting any further posts.

traceback()[source]

The formatted traceback of the last exception in the model thread

wait_on_work()[source]

Wait for all work to be finished, this function should only be used to do unit testing and such, since it will block the calling thread until all work is done

camelot.view.model_thread.model_function(original_function)[source]

Decorator to ensure a function is only called from within the model thread. If this function is called in another thread, an exception will be thrown

camelot.view.model_thread.object_thread(self)[source]

Funtion to verify if a call to an object is made in the thread of this object, to be used in assert statements. Example

class FooObject( QtCore.QObject ):

    def do_something( self ):
        assert object_thread( self )
        print 'safe method call'
Parameters:self – a QtCore.QObject instance.
Return True:if the thread of self is the current thread

The approach with assert statements is prefered over decorators, since decorators hide part of the method signature from the sphinx documentation.

camelot.view.model_thread.post(request, response=None, exception=None, args=())[source]

Post a request and a response to the default model thread

camelot.view.model_thread.setup_model()[source]

Call the setup_model function in the settings

Previous topic

mainwindow

Next topic

no_thread_model_thread

This Page