efl.ecore.Exe Class

class efl.ecore.Exe(exe_cmd, int flags=0, data=None)

This function forks and runs the given command using /bin/sh.

Note that the process handle is only valid until a child process terminated event is received. After all handlers for the child process terminated event have been called, the handle will be freed by Ecore. In this case the Python wrapper becomes “shallow” and all operations will fail or return bogus/dummy values, although it should not crash.

This class behavior is configurable by means of given constructor flags, that will make Ecore monitor process’ stdout and stderr, emitting events on main loop.

To write use send(). To read listen to ECORE_EXE_EVENT_DATA or ECORE_EXE_EVENT_ERROR events (see below). Ecore may buffer read and error data until a newline character if asked for with the flags. All data will be included in the events (newlines will be replaced with NULLS if line is buffered).

ECORE_EXE_EVENT_DATA events will only happen if the process is run with ECORE_EXE_PIPE_READ enabled in the flags. The same with the error version. Writing will only be allowed with ECORE_EXE_PIPE_WRITE enabled in the flags.

Instance Event Handling

To make use easier, there are methods that automatically filter events for this instance and deletes them when the Exe is deleted:

  • on_add_event_add()

  • on_add_event_del()

  • on_del_event_add()

  • on_del_event_del()

  • on_data_event_add()

  • on_data_event_del()

  • on_error_event_add()

  • on_error_event_del()

The callback signatures are:

func(exe, event, *args, **kargs)

In contrast with C-api conformant functions. This only receives the events from this exact exe instance. The signature is also very different, the first parameter is the Exe reference and the return value does not removes the event listener!

Using this method is likely more efficient than the C-api since it will not convert from C to Python lots of times, possibly useless.

However, there are C-api conformat functions as well.

Event Handling (C-api conformant)

Getting data from executed processed is done by means of event handling, which is also used to notify whenever this process really started or died.

One should listen to events in the main loop, such as:

EventExeAdd

listen with on_exe_add_event_add() to know when sub processes were started and ready to be used.

EventExeDel

listen with on_exe_del_event_add() to know when sub processes died.

EventExeData

listen with on_exe_data_event_add() to know when sub processes output data to their stdout.

EventExeError

listen with on_exe_error_event_add() to know when sub processes output data to their stderr.

Events will have the following signature, as explained in EventHandler:

func(event, *args, **kargs): bool

That mean once registered, your callback func will be called for all known Exe instances (that were created from Python!). You can query which instance created such event with event.exe property. Thus you often need to filter if the event you got is from the instance you need! (This is designed to match C-api).

Once your function returns evaluates to False (note: not returning means returning None, that evaluates to False!), your callback will not be called anymore and your handler is deleted.

One may delete handlers explicitly with EventHandler.delete() method.

Parameters
  • exe_cmd (str) – command to execute as subprocess.

  • flags (int) –

    if given (!= 0), should be bitwise OR of

    ECORE_EXE_PIPE_READ

    Exe Pipe Read mask

    ECORE_EXE_PIPE_WRITE

    Exe Pipe Write mask

    ECORE_EXE_PIPE_ERROR

    Exe Pipe error mask

    ECORE_EXE_PIPE_READ_LINE_BUFFERED

    Reads are buffered until a newline and delivered 1 event per line.

    ECORE_EXE_PIPE_ERROR_LINE_BUFFERED

    Errors are buffered until a newline and delivered 1 event per line.

    ECORE_EXE_PIPE_AUTO

    stdout and stderr are buffered automatically

    ECORE_EXE_RESPAWN

    Exe is restarted if it dies

    ECORE_EXE_USE_SH

    Use /bin/sh to run the command.

    ECORE_EXE_NOT_LEADER

    Do not use setsid() to have the executed process be its own session leader

    ECORE_EXE_TERM_WITH_PARENT

    Makes child receive SIGTERM when parent dies

    ECORE_EXE_ISOLATE_IO

    Try and isolate stdin/out and err of the process so it isn’t shared with the parent. Since 1.21

  • data – extra data to be associated and available with data_get()

class efl.ecore.EventExeAdd

This event notifies that the process created with Exe has been started.

Variables

exe (Exe) – Instance of Exe that created this event.

class efl.ecore.EventExeDel

This event notifies that the process created with Exe is now dead.

Variables
  • exe (Exe) – Instance of Exe that created this event.

  • pid (int) – Process ID

  • exit_code (int) – Exit code

  • exit_signal (int) – Exit signal

  • exited (bool) – Has process exited

  • signalled (bool) – Has process been signalled

class efl.ecore.EventExeData

This event is issued by Exe instances created with flags that allow reading from either stdout or stderr.

Variables
  • exe (Exe) – Instance of Exe that created this event.

  • data (string) – The raw string buffer with binary data from child process.

  • size (int) – The size of data (same as len(data))

  • lines (list) – List of strings with all text lines