From ad27496e3d42af36bbb19176dd70d2635171bd1f Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 25 Aug 2017 20:02:19 +0200 Subject: [PATCH] wait for the screen is complete --- src/fenrir/screenDriver/vcsaDriver.py | 21 +++++++++++++++------ src/fenrir/utils/screen_utils.py | 13 +++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index 56aab35b..5b47df29 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -128,8 +128,8 @@ class driver(): currScreen = str(tty.read()[3:-1]) oldScreen = currScreen watchdog = select.epoll() - watchdog.register(vcsa[currScreen], select.EPOLLPRI) - watchdog.register(tty, select.EPOLLPRI) + watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR) + watchdog.register(tty, select.POLLPRI | select.POLLERR) lastScreenContent = b'' while active.value == 1: changes = watchdog.poll(2) @@ -146,7 +146,7 @@ class driver(): except: pass try: - watchdog.register(vcsa[ currScreen ], select.EPOLLPRI) + watchdog.register(vcsa[ currScreen ], select.POLLPRI | select.POLLERR) except: pass oldScreen = currScreen @@ -158,9 +158,18 @@ class driver(): lastScreenContent = b'' else: self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO) - vcsa[currScreen].seek(0) - screenContent = vcsa[currScreen].read() - if screenContent != lastScreenContent: + vcsa[currScreen].seek(0) + dirtyContent = vcsa[currScreen].read() + screenContent = b'' + timeout = time.time() + if dirtyContent != lastScreenContent: + while screenContent != dirtyContent: + screenContent = dirtyContent + if time.time() - timeout > 0.2: + break + vcsa[currScreen].seek(0) + dirtyContent = vcsa[currScreen].read() + time.sleep(0.01) eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":None}) lastScreenContent = screenContent except Exception as e: diff --git a/src/fenrir/utils/screen_utils.py b/src/fenrir/utils/screen_utils.py index 432f1aac..267bcdad 100644 --- a/src/fenrir/utils/screen_utils.py +++ b/src/fenrir/utils/screen_utils.py @@ -7,6 +7,9 @@ from core import debug from collections import Counter import string +from select import select +from select import epoll +import select def removeNonprintable(text): # Get the difference of all ASCII characters from the set of printable characters @@ -20,6 +23,16 @@ def insertNewlines(string, every=64): def splitEvery(toSplit, every=64): return list(toSplit[i:i+every] for i in range(0, len(toSplit), every)) +def hasMoreRead(fd): + r, w, e = select([fd], [], [], 0) + return (fd in r) + +def hasMorePollPri(fd): + p = epoll() + p.register(fd, select.POLLPRI | select.POLLERR) + r = p.poll(0) + return (fd in r) + def trackHighlights(oldAttr, newAttr, text, lenght): result = '' currCursor = None