Hi
Le 29/01/2014 18:36, Victor Stinner a écrit :
Does it mean that I need to call explicitly policy.new_event_loop()
and then policy.set_event_loop(loop) if I want to use a loop in a
thread different than the main thread?
_UnixDefaultEventLoopPolicy._init_watcher() does nothing if it is
called from a thread different than the main thread.
If the user did not create a watcher, then default behaviour is to
create a default one automatically the first time it is used (just like
the default main thread loop is created).
If the watcher happens to be created from a secondary thread, it is not
possible to enable it immediately because signal.signal() would raise an
exception.
Does it mean that
it is not possible to run an event loop running subprocesses from a
thread diferent than the main thread?
Yes it is possible (this is the very purpose of the watcher)
I can understand that only one event loop can install an handler sor
SIGCHLD signal, but why not allowing to run it in a different thread?
This is just the way the default policy implements it. It's
straightforward since python does not allow catching signals in
secondary threads.
If necessary it is still possible to override it by reimplementing the
policy. This is what the GLib port does actually. The watcher is not
tied to any python thread, SIGCHLD is caught in C by glib and reported
to the thread running the default glib context, which may or may not be
the main thread.
https://bitbucket.org/a_ba/gbulb/src/1b59e8927fdeb043b140317e34045e3cd7681e13/gbulb/glib_events.py?at=master#cl-643
I just modified get_child_watcher() to add an optional loop parameter
in my subprocess_stream branch, so it's possible to run unit tests
with set_event_loop(None).
http://code.google.com/p/tulip/source/detail?r=f9e077be6d3b97fde52b10131224d75696a0cbdf&name=subprocess_stream
I think it may be confusing to expose this in the public API
(intuitively one may think that get_child_watcher(loop) means get the
watcher attached to the loop 'loop'). Is there a case where a user would
need to tune this parameter ?
Anthony