fsleyes_props.callqueue
This module provides the CallQueue class, which is used by
PropertyValue instances to enqueue and execute property listener
callback functions.
- class fsleyes_props.callqueue.Call(func, name, args, kwargs)[source]
 Bases:
objectA little class which is used to represent function calls that are on the queue.
- class fsleyes_props.callqueue.CallQueue(skipDuplicates=False)[source]
 Bases:
objectA queue of functions to be called. Functions can be enqueued via the
call()orcallAll()methods.Create a
CallQueueinstance.If
skipDuplicatesisTrue, a function which is already on the queue will be silently dropped if an attempt is made to add it again.Note
The
skipDuplicatestest is based solely on the name of the function. This means that theCallQueuedoes not support enqueueing the same function with different arguments.Testing for function and argument equality is a difficult task:
I can’t take the hash of the arguments, as I can’t assume that they are hashable (e.g.
numpyarrays).I can’t test for identity, as things which have the same value may not have the same id (e.g. strings).
I can’t test argument equality, because in some cases the argument may be a mutable type (e.g. a
list), and its value may have changed between the time the function was queued, and the time it is called. And the arguments might be big (again,numpyarrays), so an equality test could be expensive.
So this is quite a pickle. Something to come back to if things are breaking because of it.
Holding the queue
The
hold()method temporarily stops theCallQueuefrom queueing and executing functions. Any functions which are enqueued while the queue is held are kept in a separate queue. The queue is released via therelease()method, after which any held functions may be accessed via theclearHeld()method (which also clears the internal queue of held functions). Once the queue has been released, these held functions can be re-queued as normal via thecall()orcallAll()methods.- dequeue(name)[source]
 If the specified function is on the queue, it is (effectively) dequeued, and not executed.
If
skipDuplicatesisFalse, and more than one function of the same name is enqueued, they are all dequeued.
- call(func, name, *args, **kwargs)[source]
 Enqueues the given function, and calls all functions in the queue
(unless the call to this method was as a result another function being called from the queue).
- callAll(funcs)[source]
 Enqueues all of the given functions, and calls all functions in the queue.
(unless the call to this method was as a result another function being called from the queue).
Assumes that the given
funcsparameter is a list of(function, name, args, kwargs)tuples.