Package portage :: Package util :: Package _eventloop :: Module EventLoop :: Class EventLoop
[hide private]

Class EventLoop

source code

object --+
         |
        EventLoop

An event loop, intended to be compatible with the GLib event loop. Call the iteration method in order to execute one iteration of the loop. The idle_add and timeout_add methods serve as thread-safe means to interact with the loop's thread.

Nested Classes [hide private]
  _child_callback_class
  _idle_callback_class
  _io_handler_class
  _timeout_handler_class
Instance Methods [hide private]
 
__init__(self, main=True)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_new_source_id(self)
Generate a new source id.
source code
 
_poll(self, timeout=None)
All poll() calls pass through here.
source code
 
iteration(self, *args)
Like glib.MainContext.iteration(), runs a single iteration.
source code
 
_get_poll_timeout(self) source code
 
child_watch_add(self, pid, callback, data=None)
Like glib.child_watch_add(), sets callback to be called with the user data specified by data when the child indicated by pid exits.
source code
 
_sigchld_sig_cb(self, signum, frame) source code
 
_sigchld_io_cb(self, fd, events) source code
 
_poll_child_processes(self) source code
int
idle_add(self, callback, *args)
Like glib.idle_add(), if callback returns False it is automatically removed from the list of event sources and will not be called again.
source code
 
_run_idle_callbacks(self) source code
 
timeout_add(self, interval, function, *args)
Like glib.timeout_add(), interval argument is the number of milliseconds between calls to your function, and your function should return False to stop being called, or True to continue being called.
source code
 
_run_timeouts(self) source code
int
io_add_watch(self, f, condition, callback, *args)
Like glib.io_add_watch(), your function should return False to stop being called, or True to continue being called.
source code
 
source_remove(self, reg_id)
Like glib.source_remove(), this returns True if the given reg_id is found and removed, and False if the reg_id is invalid or has already been removed.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  supports_multiprocessing = True
  _sigchld_interval = 250
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, main=True)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • main (bool) - If True then this is a singleton instance for use in the main thread, otherwise it is a local instance which can safely be use in a non-main thread (default is True, so that global_event_loop does not need constructor arguments)
Overrides: object.__init__

_new_source_id(self)

source code 

Generate a new source id. This method is thread-safe.

_poll(self, timeout=None)

source code 

All poll() calls pass through here. The poll events are added directly to self._poll_event_queue. In order to avoid endless blocking, this raises StopIteration if timeout is None and there are no file descriptors to poll.

iteration(self, *args)

source code 

Like glib.MainContext.iteration(), runs a single iteration. In order
to avoid blocking forever when may_block is True (the default),
callers must be careful to ensure that at least one of the following
conditions is met:
        1) An event source or timeout is registered which is guaranteed
                to trigger at least on event (a call to an idle function
                only counts as an event if it returns a False value which
                causes it to stop being called)
        2) Another thread is guaranteed to call one of the thread-safe
                methods which notify iteration to stop waiting (such as
                idle_add or timeout_add).
These rules ensure that iteration is able to block until an event
arrives, without doing any busy waiting that would waste CPU time.
@type may_block: bool
@param may_block: if True the call may block waiting for an event
        (default is True).
@rtype: bool
@return: True if events were dispatched.

child_watch_add(self, pid, callback, data=None)

source code 

Like glib.child_watch_add(), sets callback to be called with the
user data specified by data when the child indicated by pid exits.
The signature for the callback is:

        def callback(pid, condition, user_data)

where pid is is the child process id, condition is the status
information about the child process and user_data is data.

@type int
@param pid: process id of a child process to watch
@type callback: callable
@param callback: a function to call
@type data: object
@param data: the optional data to pass to function
@rtype: int
@return: an integer ID

idle_add(self, callback, *args)

source code 

Like glib.idle_add(), if callback returns False it is automatically removed from the list of event sources and will not be called again. This method is thread-safe.

Parameters:
  • callback (callable) - a function to call
Returns: int
an integer ID

timeout_add(self, interval, function, *args)

source code 

Like glib.timeout_add(), interval argument is the number of milliseconds between calls to your function, and your function should return False to stop being called, or True to continue being called. Any additional positional arguments given here are passed to your function when it's called. This method is thread-safe.

io_add_watch(self, f, condition, callback, *args)

source code 

Like glib.io_add_watch(), your function should return False to stop being called, or True to continue being called. Any additional positional arguments given here are passed to your function when it's called.

Parameters:
  • f (int or object with fileno() method) - a file descriptor to monitor
  • condition (int) - a condition mask
  • callback (callable) - a function to call
Returns: int
an integer ID of the event source