繁体   English   中英

python3 gi:GtkTextBuffer核心转储

[英]Python3 gi: GtkTextBuffer core dump

我将python3与gi.repository.Gtk结合使用,试图通过GtkTextBufferGtkTextView显示多行文本。

基本上,我使用_addLine方法动态添加行,该方法以这种方式更新文本缓冲区( self._lines是数组,而self._textBufferGtkTextBuffer ):

def _addLine(self, text):
    if len(self._lines) == self._maxLines:
        self._lines = self._lines[1:]
    self._lines.append(text)
    content = '\n'.join(self._lines)
    print("TIC: %d" % len(content))
    self._textBuffer.set_text(content)
    print("TAC")

不幸的是,在i随机值(小于self._maxLines或大于self._maxLines )时,我会在“ TIC”和“ TAC”之间随机获得一个核心转储,因此当我尝试设置缓冲区的内容时。

此方法由线程调用,该线程自己从构造函数调用(在初始化所有GUI元素之后):

def _startUpdateThread(self):
    thread = threading.Thread(target=lambda: self._updateLoop())
    thread.daemon = True
    thread.start()

def _updateLoop(self):
    i=0
    for l in listings.tail(self._logFile, follow=True, n=1000):
        i+=1
        print("i=%d, nLines=%d" % (i, len(self._lines)))
        self._addLine(l)

我正在使用结构如下的Glade构建器:

GtkWindow
  - GtkVBox
      - GtkScrolledWindow
          - GtkTextView (linked to GtkTextBuffer)
  - GtkButton (to close the window)
  - GtkTextBuffer

我做错了什么? 发生核心转储的原因是什么?

非常感谢你的帮助。

从线程而不是GTK主循环修改窗口小部件时,应使用GLib.idle_add()

在这种情况下:

GLib.idle_add(self._textBuffer.set_text, content)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM