Classes for Tracking Objects

This module contains a simple tracker implementation which makes it easy to directly track your own objects. It also defines a mixin which defines the tracking protocol.

Tracker - A Simple Tracker Implementation

class pytracker.Tracker

Bases: pytracker.tracker.TrackerMixin, dict

This is a sample tracker object which can be used directly, or as a model for implementing custom tracker objects.

type_tracker

Class variable to specify the class used to track types

alias of TrackedType

dump(output=None)

Dumps the object tracking table to stdout or to the given file object.

notify_attached(*args)

Triggered whenever a new trackable object is created.

notify_destroyed(*args)

Triggered when an object being tracked is freed.

notify_detached(*args)

Triggered whenver an existing trackable object is no longer being racked.

notify_updated(*args)

Triggered when the data bundle for a currently tracked object is changed.

reset_object_tracking(cls)

Clears any tracked objects for the given class. Does nothing if object tracking is not enabled for this class.

set_object_tracking(cls, enable=True)

Enables tracking of objects for the given class. If tracking is disabled, all object history is lost.

class pytracker.TrackedType

Bases: object

Internal class used to track a given object type. May be subclassed and assigned to pytracker.Tracker.type_tracker to override the default implementation.

dump_objects(output=None)

Prints the status of all allocated objects for this type to stdout or an optional file object.

track(serial, objtype, bundle)

Called by the tracker to register tracking for a given live object.

untrack(serial, objtype, bundle)

Called by the tracker to indicate that an object is no longer live.

allocated = 0

Contains the number of instances currently allocated for the type

deallocated = 0

Contains the number of instances which have been deallocated

objects = None

Contains an optional dictionary for tracking objects by serial number

objtype = None

Contains the type of the tracked object

track_objects

Set to True to track objects individually. Defaults to False.

TrackerMixin - Protocol Mixin for Trackers

class pytracker.TrackerMixin

Bases: object

This class defines the protocol which must be supported by objects which are assigned to trackable objects using Trackable._set_tracker() or pytracker.set_global_tracker().

Note that the pytracker.Trackable class does not require that all of these methods be defined. In fact, if they are not defined, there will be no error and the notification will not be sent. As a rule, however, it is best to subclass the TrackerMixin class, as additional methods may be added in the future.

notify_attached(serial, obj_type, bundle)

Whenever a trackable object is first assigned to a tracker, this method is triggered.

Parameters:
  • serial – The unique serial number fo the trackable object.
  • obj_type – The type of the object, essentially type(obj).
  • bundle – The bundle object which may contain useful tracking information.
notify_destroyed(serial, obj_type, bundle)

Just before a trackable object is freed, this method is triggered.

Parameters:
  • serial – The unique serial number fo the trackable object.
  • obj_type – The type of the object, essentially type(obj).
  • bundle – The bundle object which may contain useful tracking information.
notify_detached(serial, obj_type, bundle)

Just before a trackable object is assigned an alternate tracker (or None) this method is triggered.

Parameters:
  • serial – The unique serial number fo the trackable object.
  • obj_type – The type of the object, essentially type(obj).
  • bundle – The bundle object which may contain useful tracking information.
notify_updated(serial, obj_type, bundle)

If the bundle associated with a trackable object is changed, this method is triggered.

Parameters:
  • serial – The unique serial number fo the trackable object.
  • obj_type – The type of the object, essentially type(obj).
  • bundle – The bundle object which may contain useful tracking information.

Table Of Contents

Previous topic

Making Objects Trackable

This Page