model_thread Package — Camelot documentation

### Navigation

- index
- modules |
- Camelot documentation »

# model_thread Package

## `model_thread` Package

class `camelot.view.model_thread.` `AbstractModelThread`(setup_thread=<function setup_model at 0x9569ae4>)

  Bases: `PyQt4.QtCore.QThread`

  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`()

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

  `post`(request, response=None, exception=None, args=())

    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

  `run`()
  `setup_exception_signal`
  `stop`()

    Stop the model thread from accepting any further posts.

  `thread_busy_signal`
  `traceback`()

    The formatted traceback of the last exception in the model thread

  `wait_on_work`()

    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

exception `camelot.view.model_thread.` `ModelThreadException`

  Bases: `exceptions.Exception`

`camelot.view.model_thread.` `construct_model_thread`(*args, **kwargs)

`camelot.view.model_thread.` `get_model_thread`()

`camelot.view.model_thread.` `gui_function`(original_function)

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

`camelot.view.model_thread.` `has_model_thread`()

`camelot.view.model_thread.` `model_function`(original_function)

  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.` `post`(request, response=None, exception=None, args=())

  Post a request and a response to the default model thread

`camelot.view.model_thread.` `setup_model`()

  Call the setup_model function in the settings

## `garbage_collector` Module

class `camelot.view.model_thread.garbage_collector.` `GarbageCollector`(parent, debug=False)

  Bases: `PyQt4.QtCore.QObject`

  Disable automatic garbage collection and instead collect manually every INTERVAL milliseconds.

  This is done to ensure that garbage collection only happens in the GUI thread, as otherwise Qt can crash.

  This code is serves as a workaround for a bug in PyQt:

  and is modeled after the original code of Kovid Goyal

  `INTERVAL` = 5000

## `no_thread_model_thread` Module

Created on Sep 12, 2009

@author: tw55413

class `camelot.view.model_thread.no_thread_model_thread.` `NoThreadModelThread`(setup_thread=<function setup_model at 0x9569ae4>)

  Bases: `camelot.view.model_thread.AbstractModelThread`

  `isRunning`()
  `post`(request, response=None, exception=None, args=())
  `start`()
  `wait_on_work`()

## `signal_slot_model_thread` Module

Created on Sep 9, 2009

@author: tw55413

class `camelot.view.model_thread.signal_slot_model_thread.` `SignalSlotModelThread`(setup_thread=<function setup_model at 0x9569ae4>)

  Bases: `camelot.view.model_thread.AbstractModelThread`

  A model thread implementation that uses signals and slots to communicate between the model thread and the gui thread

  there is no explicit model thread verification on these methods, since this model thread might not be THE model thread.

  `busy`(*args, **kwargs)

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

  `pop`(*args, **kwargs)

    Pop a task from the queue, return None if the queue is empty

  `post`(*args, **kwargs)
  `run`()
  `stop`(*args, **kwargs)
  `task_available`
  `wait_on_work`(*args, **kwargs)

    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

class `camelot.view.model_thread.signal_slot_model_thread.` `Task`(request, name='', args=())

  Bases: `PyQt4.QtCore.QObject`

  `clear`()

    clear this tasks references to other objects

  `exception`
  `execute`()
  `finished`

class `camelot.view.model_thread.signal_slot_model_thread.` `TaskHandler`(queue)

  Bases: `PyQt4.QtCore.QObject`

  A task handler is an object that handles tasks that appear in a queue, when its handle_task method is called, it will sequentially handle all tasks that are in the queue.

  `busy`()

    Return True/False:
    | indicating if this task handler is busy

  `handle_task`()

    Handle all tasks that are in the queue

  `task_handler_busy_signal`

### Navigation

- index
- modules |
- Camelot documentation »

Comments
blog comments powered by Disqus