wand.resource — Global resource management¶
There is the global resource to manage in MagickWand API. This module implements automatic global resource management through reference counting.
-
wand.resource.genesis()¶ Instantiates the MagickWand API.
Warning
Don’t call this function directly. Use
increment_refcount()anddecrement_refcount()functions instead.
-
wand.resource.terminus()¶ Cleans up the MagickWand API.
Warning
Don’t call this function directly. Use
increment_refcount()anddecrement_refcount()functions instead.
-
wand.resource.increment_refcount()¶ Increments the
reference_countand instantiates the MagickWand API if it is the first use.
-
wand.resource.decrement_refcount()¶ Decrements the
reference_countand cleans up the MagickWand API if it will be no more used.
-
class
wand.resource.Resource¶ Abstract base class for MagickWand object that requires resource management. Its all subclasses manage the resource semiautomatically and support
withstatement as well:with Resource() as resource: # use the resource... pass
It doesn’t implement constructor by itself, so subclasses should implement it. Every constructor should assign the pointer of its resource data into
resourceattribute inside ofwithallocate()context. For example:class Pizza(Resource): '''My pizza yummy.''' def __init__(self): with self.allocate(): self.resource = library.NewPizza()
New in version 0.1.2.
-
allocate(**kwds)¶ Allocates the memory for the resource explicitly. Its subclasses should assign the created resource into
resourceattribute inside of this context. For example:with resource.allocate(): resource.resource = library.NewResource()
-
c_clear_exception= NotImplemented¶ (
ctypes.CFUNCTYPE) Thectypesfunction that clears an exception of theresource.Note
It is an abstract attribute that has to be implemented in the subclass.
-
c_destroy_resource= NotImplemented¶ (
ctypes.CFUNCTYPE) Thectypesfunction that destroys theresource.Note
It is an abstract attribute that has to be implemented in the subclass.
-
c_get_exception= NotImplemented¶ (
ctypes.CFUNCTYPE) Thectypesfunction that gets an exception from theresource.Note
It is an abstract attribute that has to be implemented in the subclass.
-
c_is_resource= NotImplemented¶ (
ctypes.CFUNCTYPE) Thectypespredicate function that returns whether the given pointer (that contains a resource data usuaully) is a valid resource.Note
It is an abstract attribute that has to be implemented in the subclass.
-
destroy()¶ Cleans up the resource explicitly. If you use the resource in
withstatement, it was called implicitly so have not to call it.
-
get_exception()¶ Gets a current exception instance.
Returns: a current exception. it can be Noneas well if any errors aren’t occurredReturn type: wand.exceptions.WandException
-
raise_exception(stacklevel=1)¶ Raises an exception or warning if it has occurred.
-
resource¶ Internal pointer to the resource instance. It may raise
DestroyedResourceErrorwhen the resource has destroyed already.
-
-
exception
wand.resource.DestroyedResourceError¶ An error that rises when some code tries access to an already destroyed resource.
Changed in version 0.3.0: It becomes a subtype of
wand.exceptions.WandException.