ruby tk和fork with exit导致中止:" [xcb]处理队列时的序列号未知"

时间:2016-10-16 07:30:58

标签: ruby multithreading fork tk

使用tk和ruby 1.9.3一起工作,我发现我无法在主循环中进行调用"退出" - 我需要做一些像exec()这样的事情来摆脱分叉。

示例程序:

#!/usr/bin/ruby
require 'tk'

root = TkRoot.new 

def doit
  unless fork
    puts "Inside the fork"
    exit  # This is where it falls apart
  end
end 

TkButton.new(root) {
  text 'go'
  command proc { doit }
}.pack

Tk.mainloop()

按下按钮,我们正确分叉,但是当叉子呼叫'退出'然后我们得到:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
ruby: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
ruby: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

我发现我可以通过使用" exec(' echo')"这样的东西来破解变通方法。而不是退出,但这只是愚蠢的。那个出口上的什么不起作用?有没有办法从ruby中调用XInitThreads(这不是jruby或fxruby)我可以使用并且会有帮助吗?

从我的研究到目前为止,似乎ruby和Tk在你引入线程或分叉的那一刻都很破碎,但是我找不到一个干净的方法来处理这个问题。

1 个答案:

答案 0 :(得分:0)

任何使用线程支持构建的Tcl都存在此问题。

您必须重新构建程序,以便Tcl / Tk进程是独立的实体,并且不会分叉。

gui需要将任何输入命令发送到相应的ruby线程,并且线程需要将数据发送到gui才能显示。