odnochlen
Создаешь отдельный поток, читаешь им stdout и выводишь прочитанное. Писать в stdin не надо?
Из второго потока не получается писать в textctrl, созданным основным потоком. Что делать?
import re
import os
import subprocess
import wx
import string
import threading
from itertools import count
class MyThread(threading.Thread):
textArea = 0
pp = 0
def __init__(self, pp, textArea):
self.pp = pp
self.textArea = textArea
threading.Thread.__init__(self)
def run(self):
for i in count(1):
oo = self.pp.stdout.readline()
self.textArea.AppendText("oo") ##От этого умирает
class LaucherFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, id=-1, parent=None,
pos=wx.Point(400, 200), size=wx.Size(830, 640), title='Система запуска ИРК')
self.panel = wx.Panel(self)
self.imitator = wx.TextCtrl(self, pos=(10,20), size=(400,300), style = wx.TE_MULTILINE)
pp = subprocess.Popen(
["yes"]
,shell = True, stdout=subprocess.PIPE
)
MyThread(pp, self.imitator).start()
class HelloApp(wx.App):
def OnInit(self):
frame = LaucherFrame()
frame.Show(True)
return True
if __name__ == '__main__':
app = HelloApp()
app.MainLoop()
Вывод ошибки:
(python:2108): Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
(python:2108): Gtk-CRITICAL **: IA__gtk_text_layout_wrap_loop_start: assertion `layout->one_style_cache == NULL' failed
(python:2108): Gtk-CRITICAL **: IA__gtk_text_layout_wrap_loop_end: assertion `layout->wrap_loop_count > 0' failed
(python:2108): Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
(python:2108): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion `layout->wrap_loop_count == 0' failed
(python:2108): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion `layout->wrap_loop_count == 0' failed
(python:2108): Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
(python:2108): Pango-CRITICAL **: pango_layout_get_iter: assertion `PANGO_IS_LAYOUT (layout)' failed
Ошибка сегментирования
adeykin@adeykin-System-Product-Name:~/Документы/test$ yes: стандартный вывод: Обрыв канала
yes: ошибка записи