[gedit] Make SIGALRM timeout for snippets optional



commit 6512fbdd4ddad13594a9fb82ac62e4e79bf7b59f
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Jan 24 14:31:46 2010 +0100

    Make SIGALRM timeout for snippets optional
    
    SIGALRM is not supported on windows. This makes python/shell
    placeholders potentially blocking gedit, but it's better than disabling
    them altogether.

 plugins/snippets/snippets/Placeholder.py |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/plugins/snippets/snippets/Placeholder.py b/plugins/snippets/snippets/Placeholder.py
index d91405d..8a5b994 100644
--- a/plugins/snippets/snippets/Placeholder.py
+++ b/plugins/snippets/snippets/Placeholder.py
@@ -522,10 +522,21 @@ class PlaceholderEval(PlaceholderExpand):
 
                 return mirrors
 
+        # SIGALRM is not supported on all platforms (e.g. windows). Timeout
+        # with SIGALRM will not be used on those platforms. This will
+        # potentially block gedit if you have a placeholder which gets stuck,
+        # but it's better than not supporting them at all. At some point we
+        # might have proper thread support and we can fix this in a better way
+        def timeout_supported(self):
+                return hasattr(signal, 'SIGALRM')
+
         def timeout_cb(self, signum = 0, frame = 0):
                 raise TimeoutError, "Operation timed out (>2 seconds)"
         
         def install_timeout(self):
+                if not self.timeout_supported():
+                        return
+
                 if self.timeout_id != None:
                         self.remove_timeout()
                 
@@ -533,6 +544,9 @@ class PlaceholderEval(PlaceholderExpand):
                 signal.alarm(2)
                 
         def remove_timeout(self):
+                if not self.timeout_supported():
+                        return
+
                 if self.timeout_id != None:
                         signal.alarm(0)
                         



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