efl.ecore.Exe
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:
listen with on_exe_add_event_add()
to know when sub processes
were started and ready to be used.
listen with on_exe_del_event_add()
to know when sub processes died.
listen with on_exe_data_event_add()
to know when sub processes
output data to their stdout.
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.
exe_cmd (str) – command to execute as subprocess.
flags (int) –
if given (!= 0), should be bitwise OR of
Exe Pipe Read mask
Exe Pipe Write mask
Exe Pipe error mask
Reads are buffered until a newline and delivered 1 event per line.
Errors are buffered until a newline and delivered 1 event per line.
stdout and stderr are buffered automatically
Exe is restarted if it dies
Use /bin/sh to run the command.
Do not use setsid() to have the executed process be its own session leader
Makes child receive SIGTERM when parent dies
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()
efl.ecore.
EventExeAdd
¶This event notifies that the process created with Exe
has been started.
efl.ecore.
EventExeDel
¶This event notifies that the process created with Exe
is now dead.