[chrome-gnome-shell] Avoid thread blocking using select function



commit 517aeb0478ac2480eebdb018c9f1aa7cd984e05f
Author: Yuri Konotopov <ykonotopov gmail com>
Date:   Sat Jul 30 22:56:02 2016 +0300

    Avoid thread blocking using select function

 connector/gs-chrome-connector.py |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/connector/gs-chrome-connector.py b/connector/gs-chrome-connector.py
index 5b49dbb..3dea5c3 100755
--- a/connector/gs-chrome-connector.py
+++ b/connector/gs-chrome-connector.py
@@ -18,6 +18,7 @@ import os
 import struct
 import sys
 import re
+from select import select
 from threading import Thread, Lock
 
 CONNECTOR_VERSION      = 6.1
@@ -89,11 +90,15 @@ def read_thread_func(proxy, mainLoop):
     settings = Gio.Settings.new(SHELL_SCHEMA)
 
     while mainLoop.is_running():
-        # Read the message length (first 4 bytes).
-        if BUFFER_SUPPORTED:
-            text_length_bytes = sys.stdin.buffer.read(4)
+        rlist, _, _ = select([sys.stdin], [], [], 1)
+        if rlist:
+            # Read the message length (first 4 bytes).
+            if BUFFER_SUPPORTED:
+                text_length_bytes = sys.stdin.buffer.read(4)
+            else:
+                text_length_bytes = sys.stdin.read(4)
         else:
-            text_length_bytes = sys.stdin.read(4)
+            continue
 
         if len(text_length_bytes) == 0:
             mainLoop.quit()


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