私は最初の投稿ですので、何か間違っていたら忍耐してください。
私は、gtkインターフェイスを持つPythonで書かれた非常に簡単なチャットプログラムに取り組んでいます。ユーザはサーバを持ち、もう1人はクライアントを持っています。私は(接続が確立されていても)メッセージを送受信できないことを除いて、すべて動作しています。私はすでにフォーラムで解決策を探していましたが、何も見つかりませんでした。
Gdk-ERROR in Python guiマルチスレッドの場合
gi.require_version ('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject, GLib
class GUI:
def __init__ (self, is_server):
GObject.threads_init()
[...]
self.buffer1 = Gtk.TextBuffer()
self.text_box = Gtk.TextView (buffer=self.buffer1)
self.text_box.set_editable (False)
[...]
self.th = threading.Thread (target = self.receive)
self.th.daemon = True
self.th.start()
Gtk.main()
def receive (self):
while (True):
try:
msg = self.socket.receive_message()
if (msg != ""): self.insert_text (msg)
except: pass
def insert_text (self, text):
self.text_box.set_editable (True)
end_iter = self.buffer1.get_end_iter()
try: self.buffer1.insert (end_iter, text + "\n")
except: pass
self.text_box.set_editable (False)
adj = self.scr.get_vadjustment()
adj.set_value (adj.get_upper())
そしてClient.py又はServer.pyに(同じラインである):GUIのコード
(の一部)であり、Iは、受信エラーがある
class Client/Server:
[...]
def receive_message (self):
try:
msg0 = self.conn.recv (1024)
msg = msg0.decode ("utf-8")
return msg
except: pass
。私はMULとかなり新しいです(
(Chat.py:61330): Gdk-ERROR **: The program 'Chat.py' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadRequest (invalid request code or no such operation)'.
(Details: rerial 892 error_code 1 request_code 0 (core protocol) minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the GDK_SYNCHRONIZE environment
variable to change this behavior. You can get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
Trace/BPT trap (code dumped)
は、私は2番目のスレッドで私はGtk.TextViewのテキストを変更しようとするので、それはマルチスレッド化エラーだと思うが、私はわかりませんティスディング)。
ありがとうございます。
とてもうまく動作します。 – Momolo