[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bindings/python/python-efl] master 01/01: Python-EFL: warn the user when try to use the subprocess or the signal modules, as they conflict with ecore



davemds pushed a commit to branch master.

commit bac6d9a281711ad5ca61d8c46b6d6bb52a37ecd9
Author: davemds <dave@gurumeditation.it>
Date:   Sun Sep 15 17:53:21 2013 +0200

    Python-EFL: warn the user when try to use the subprocess or the signal modules, as they conflict with ecore
---
 TODO                    |  1 -
 efl/ecore/efl.ecore.pyx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/TODO b/TODO
index 2690a4f..2024dd8 100644
--- a/TODO
+++ b/TODO
@@ -19,7 +19,6 @@ BUGS
 TODO
 ====
 
-* alert on signal and subprocess module usage (was in python-ecore/ecore/__init__.py)
 * evas.SmartObject
 * edje: complete the unit tests
 * elm.Web need a test
diff --git a/efl/ecore/efl.ecore.pyx b/efl/ecore/efl.ecore.pyx
index 7cb2985..6791cd1 100644
--- a/efl/ecore/efl.ecore.pyx
+++ b/efl/ecore/efl.ecore.pyx
@@ -335,3 +335,52 @@ include "efl.ecore_file_download.pxi"
 include "efl.ecore_file_monitor.pxi"
 
 init()
+
+
+#---------------------------------------------------------------------------
+# let's try to warn users that ecore conflicts with subprocess module
+import subprocess
+
+_orig_subprocess = None
+
+def subprocess_warning(*a, **ka):
+    print("""    DEVELOPER WARNING:
+        Using subprocess (Popen and derivates) with Ecore is a bad idea.
+
+        Ecore will set some signal handlers subprocess module depends and this
+        may cause this module to operate unexpectedly.
+
+        Instead of using subprocess.Popen(), please consider using Ecore's
+        Exe() class.
+        """)
+    return _orig_subprocess(*a, **ka)
+
+if subprocess.Popen is not subprocess_warning:
+    _orig_subprocess = subprocess.Popen
+    subprocess.Popen = subprocess_warning
+
+
+#---------------------------------------------------------------------------
+# also try to warn that ecore conflicts with signal module
+import signal
+
+_orig_signal = None
+
+def signal_warning(sig, action):
+    if sig in (signal.SIGPIPE, signal.SIGALRM, signal.SIGCHLD, signal.SIGUSR1,
+               signal.SIGUSR2, signal.SIGHUP,  signal.SIGQUIT, signal.SIGINT,
+               signal.SIGTERM, signal.SIGPWR):
+        print("""    DEVELOPER WARNING:
+        Ecore already defines signal handlers for:
+
+        SIGPIPE, SIGALRM, SIGCHLD, SIGUSR1, SIGUSR2
+        SIGHUP, SIGQUIT, SIGINT, SIGTERM, SIGPWR, SIGRT*
+
+        Since you're defining a new signal handler, you might collide with
+        Ecore and bad things may happen!
+        """)
+    return _orig_signal(sig, action)
+
+if signal.signal is not signal_warning:
+    _orig_signal = signal.signal
+    signal.signal = signal_warning

--