Core methods that a Reactor must implement.
Methods
|
|
addSystemEventTrigger
callFromThread
crash
fireSystemEvent
iterate
removeSystemEventTrigger
run
stop
|
|
addSystemEventTrigger
|
addSystemEventTrigger (
self,
phase,
eventType,
callable,
*args,
*kw,
)
Add a function to be called when a system event occurs.
Each "system event" in Twisted, such as startup , shutdown , and
persist , has 3 phases: before , during , and after (in that
order, of course). These events will be fired internally by the
Reactor.
An implementor of this interface must only implement those events
described here.
Callbacks registered for the "before" phase may return either None or a
Deferred. The "during" phase will not execute until all of the
Deferreds from the "before" phase have fired.
Once the "during" phase is running, all of the remaining triggers must
execute; their return values must be ignored.
Arguments:
phase: a time to call the event -- either the string before ,
after , or during , describing when to call it relative to the
event's execution.
eventType: this is a string describing the type of event. It
callable: the object to call before shutdown.
*args: the arguments to call it with.
**kw: the keyword arguments to call it with.
Returns:
an ID that can be used to remove this call with
removeSystemEventTrigger.
|
|
callFromThread
|
callFromThread (
self,
callable,
*args,
*kw,
)
Call a function from within another thread.
This should wake up the main thread (where run() is executing) and run
the given function.
I hope it is obvious from this description that this method must be
thread safe. (If you want to call a method in the next mainloop
iteration, but you're in the same thread, use callLater with a delay of
0.)
|
|
crash
|
crash ( self )
Stop the main loop immediately, without firing any system events.
This is named as it is because this is an extremely "rude" thing to do;
it is possible to lose data and put your system in an inconsistent
state by calling this. However, it is necessary, as sometimes a system
can become wedged in a pre-shutdown call.
|
|
fireSystemEvent
|
fireSystemEvent ( self, eventType )
Fire a system-wide event.
System-wide events are things like startup , shutdown , and
persist .
|
|
iterate
|
iterate ( self, delay=0 )
Run the main loop's I/O polling function for a period of time.
This is most useful in applications where the UI is being drawn "as
fast as possible", such as games.
|
|
removeSystemEventTrigger
|
removeSystemEventTrigger ( self, triggerID )
Removes a trigger added with addSystemEventTrigger.
Arguments:
|
|
run
|
run ( self )
Run the main loop until stop() is called.
|
|
stop
|
stop ( self )
Stop the main loop by firing a shutdown System Event.
|
|