From 5e676090fab44f0584a47be2137695a7c5df2a15 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Sep 2017 19:51:01 +0530 Subject: [PATCH] Report failures to write to child --- kitty/child-monitor.c | 6 ++++-- kitty/window.py | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index e0e61e211..ddef1d332 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -221,10 +221,11 @@ needs_write(ChildMonitor *self, PyObject *args) { unsigned long id, sz; const char *data; if (!PyArg_ParseTuple(args, "ks#", &id, &data, &sz)) return NULL; - if (!sz) { Py_RETURN_NONE; } + PyObject *found = Py_False; children_mutex(lock); for (size_t i = 0; i < self->count; i++) { if (children[i].id == id) { + found = Py_True; Screen *screen = children[i].screen; screen_mutex(lock, write); uint8_t *buf = PyMem_RawRealloc(screen->write_buf, screen->write_buf_sz + sz); @@ -240,7 +241,8 @@ needs_write(ChildMonitor *self, PyObject *args) { } children_mutex(unlock); if (PyErr_Occurred()) return NULL; - Py_RETURN_NONE; + Py_INCREF(found); + return found; } static PyObject * diff --git a/kitty/window.py b/kitty/window.py index 0296c849a..a016911b1 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -2,10 +2,11 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal +import sys import weakref from collections import deque -from time import monotonic from itertools import count +from time import monotonic from .char_grid import CharGrid, DynamicColor from .constants import ( @@ -112,8 +113,10 @@ class Window: def write_to_child(self, data): if data: - get_boss().child_monitor.needs_write(self.id, data) - wakeup() + if get_boss().child_monitor.needs_write(self.id, data) is True: + wakeup() + else: + print('Failed to write to child %d as it does not exist' % self.id, file=sys.stderr) def bell(self): if self.opts.enable_audio_bell: