chiark / gitweb /
Check for EOF on the serialCommunication module
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Sat, 27 Dec 2014 23:01:42 +0000 (18:01 -0500)
committerSteven Abadie <steven@alephobjects.com>
Tue, 30 Dec 2014 22:34:11 +0000 (15:34 -0700)
If Cura has terminated, stdin will be in EOF which will cause the readline
to return an empty string. By catching that, we will be abl to quit
instead of spamming stderr with [''].
Fixes #63 and possibly issue #45 as well.

Cura/serialCommunication.py

index efff5e0d04bbd461d512a6e21020de16b391d62d..efc6e72d38f0836722117a5cca9effd2348faa53 100644 (file)
@@ -51,9 +51,14 @@ class serialComm(object):
                pass
 
        def monitorStdin(self):
-               while not self._comm.isClosed():
-                       line = sys.stdin.readline().strip()
-                       line = line.split(':', 1)
+               while not (self._comm.isClosed() or sys.stdin.closed):
+                       line = sys.stdin.readline()
+                        # If readline returns an empty string it means that
+                        # we've hit stdin's EOF, probably because the parent was
+                        # closed, so we need to exit as well instead of spamming stderr.
+                        if line == '':
+                                break
+                       line = line.strip().split(':', 1)
                        if line[0] == 'STOP':
                                self._comm.cancelPrint()
                                self._gcodeList = ['M110']