systemd.login module

Python interface to the libsystemd-login library.

systemd.login.machine_names() list

Returns a list of currently running virtual machines and containers on the system. Wraps sd_get_machine_names(3).

systemd.login.seats() list

Returns a list of currently available local seats. Wraps sd_get_seats(3).

systemd.login.sessions() list

Returns a list of current login sessions. Wraps sd_get_sessions(3).

systemd.login.uids() list

Returns a list of uids of users who currently have login sessions. Wraps sd_get_uids(3).

class systemd.login.Monitor([category])

Monitor may be used to monitor login sessions, users, seats, and virtual machines/containers. Monitor provides a file descriptor which can be integrated in an external event loop.

See sd_login_monitor_new(3) for the details about what can be monitored.

close() None

Free resources allocated by this Monitor object. This method invokes sd_login_monitor_unref(). See sd_login_monitor_unref(3).

fileno() int

Get a file descriptor to poll for events. This method wraps sd_login_monitor_get_fd(3).

flush() None

Reset the wakeup state of the monitor object. This method invokes sd_login_monitor_flush(). See sd_login_monitor_flush(3).

get_events() int

Returns a mask of poll() events to wait for on the file descriptor returned by .fileno().

See sd_login_monitor_get_events(3) for further discussion.

get_timeout() int or None

Returns a timeout value for usage in poll(), the time since the epoch of clock_gettime(2) in microseconds, or None if no timeout is necessary.

The return value must be converted to a relative timeout in milliseconds if it is to be used as an argument for poll(). See sd_login_monitor_get_timeout(3) for further discussion.

get_timeout_ms() int

Returns a timeout value suitable for usage in poll(), the value returned by .get_timeout() converted to relative ms, or -1 if no timeout is necessary.

Example: polling for events

This example shows that session/uid/seat/machine events can be waited for (using e.g. poll). This makes it easy to integrate Monitor in an external event loop:

>>> import select
>>> from systemd import login
>>> m = login.Monitor("machine")        
>>> p = select.poll()
>>> p.register(m, m.get_events())       
>>> login.machine_names()               
[]
>>> p.poll()                            
[(3, 1)]
>>> login.machine_names()               
['fedora-25']