- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在 Mac OS X(10.7 和 10.8)上运行 python (2.7) Tkinter GUI 应用程序。 UI 位于一个单独的进程中,该进程使用多处理从主脚本中 fork 出来。然而,当我运行时,它失败了:
'The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY_YOU_MUST_EXEC__() to debug.'
这在 Windows 上运行得很好。
我发现了一个与它相关的错误,用 python 记录:http://bugs.python.org/issue8713但遗憾的是,看起来该修复仅在 3.x 版本中实现,但我也需要支持 2.7。
我知道还有一些关于同一错误的其他问题,如下所示:Python multiprocessing bug on Mac OS X
但我无法弄清楚在我的特定情况下什么可以真正解决问题。
关于如何让它在 Mac 上运行有什么想法吗?
代码如下。 DriverVisualizer() 创建(在另一个脚本中),它初始化另一个进程上的 UI。
from util import *
from multiprocessing import Process, Pipe
from Tkinter import *
import threading
import Queue
from time import *
class VisualizerUI:
def __init__(self, conn, count, pixelSize):
self._conn = conn
self._master = Tk()
self._q = Queue.Queue()
self._count = count
self._values = []
self._leds = []
self._pixelSize = pixelSize
self._pixelPad = int(pixelSize / 2)
self._pixelSpace = 4
#init colors to all black (off)
for i in range(self._count):
self._values.append("#000000")
self.initUI()
self._thread = threading.Thread(target=self.commThread).start()
def mainloop(self):
self._master.mainloop()
try:
self._conn.send({"status" : False})
except:
pass
def updateUI(self):
try:
for i in range(self._count):
self._canvas.itemconfig(self._leds[i], fill=self._values[i])
except TclError:
#Looks like the UI closed!
pass
def commThread(self):
data = None
error = False
while True:
#bit of a hack, but need to check occasionaly for window size change
if self._width != self._master.winfo_width() or self._height != self._master.winfo_height():
self._width = self._master.winfo_width()
self._height = self._master.winfo_height()
self._master.after_idle(self.layoutPixels)
try:
data = self._conn.recv()
except EOFError:
error = True
break
if data["run"]:
self._values = data["data"]
self.updateUI()
self._conn.send({"status" : True})
else:
break
if not error:
self._conn.send("Killing UI...")
self._master.destroy()
def layoutPixels(self):
self._canvas.config(width=self._width, height=self._height)
newRow = True
x_off = self._pixelPad
y_off = self._pixelPad
for i in range(self._count):
if (x_off + (self._pixelSize * 2) + self._pixelSpace + self._pixelPad) > self._width:
newRow = True
y_off = y_off + self._pixelPad + self._pixelSize
if newRow:
x_off = self._pixelPad
newRow = False
else:
x_off = x_off + self._pixelSize + self._pixelSpace
self._canvas.coords(self._leds[i], x_off, y_off, x_off + self._pixelSize, y_off + self._pixelSize)
y = (y_off + self._pixelSize + self._pixelPad)
if self._height != y:
self._master.geometry("{0}x{1}".format(self._width, y))
self._master.update()
def __CancelCommand(event=None):
pass
def initUI(self):
m = self._master
m.protocol('WM_DELETE_WINDOW', self.__CancelCommand)
m.title("LED Strip Visualizer")
m.geometry("1400x50")
m.update()
self._width = m.winfo_width()
self._height = m.winfo_height()
m.minsize(self._width, self._height)
self._canvas = Canvas(self._master, background="#000000")
c = self._canvas
c.pack(side=TOP)
for i in range(self._count):
index = c.create_oval(0,0,self._pixelSize,self._pixelSize, fill=self._values[i])
self._leds.append(index)
#m.bind("<Configure>", self.resize)
self.layoutPixels()
def toHexColor(r,g,b):
return "#{0:02x}{1:02x}{2:02x}".format(r,g,b)
def startUI(conn, count, pixelSize):
ui = VisualizerUI(conn, count, pixelSize)
ui.mainloop()
class DriverVisualizer(object):
"""Main driver for Visualizer UI (for testing)"""
def __init__(self, leds, pixelSize = 15, showCurrent = False):
self.leds = leds
self._showCurrent = showCurrent
if self._showCurrent:
self._peakCurrent = 0;
else:
self._peakCurrent = None
self._parent_conn, self._child_conn = Pipe()
p = Process(target=startUI, args=(self._child_conn, self.leds, pixelSize))
p.start()
sleep(0.5) # give the UI some time to spin up before throwing data at it
def __del__(self):
self._parent_conn.send({"data" : None, "run" : False})
print self._parent_conn.recv()
def calcCurrent(self, data):
c = 0
for r, g, b in data:
c = c + int(((r/255.0) * 20.0) + ((g/255.0) * 20.0) + ((b/255.0) * 20.0))
if c > self._peakCurrent:
self._peakCurrent = c
return c
#Push new data to strand
def update(self, data):
c = None
if self._showCurrent:
c = self.calcCurrent(data)
self._parent_conn.send({"data" : [toHexColor(*(data[x])) for x in range(self.leds)], "run" : True, "c" : c, "peak" : self._peakCurrent})
resp = self._parent_conn.recv()
if not resp["status"]:
error = True
parent_conn.close()
最佳答案
我遇到了同样的问题,请检查这个:
https://stackoverflow.com/a/19082049/1956309
这可以让您在此处找到 Tkinter 错误:
http://bugs.python.org/issue5527#msg195480
对我有用的解决方案(Mac OS 10.8 和 Python 2.7)是重新排列代码,以便在调用任何类型的 process.start() 之后放置“导入 Tkinter”
看起来像:
import multiprocessing
def cam_loop(the_q):
while True:
the_q.put('foo in the queue')
def show_loop(the_q):
while True:
from_queue = the_q.get()
print from_queue
if __name__ == '__main__':
try:
the_q = multiprocessing.Queue(1)
cam_process = multiprocessing.Process(target=cam_loop,args=(the_q, ))
cam_process.start()
show_process = multiprocessing.Process(target=show_loop,args=(the_q, ))
show_process.start()
import Tkinter as tk # << Here!
cam_process.join()
show_loop.join()
except KeyboardInterrupt:
cam_process.terminate()
show_process.terminate()
P.d:谢谢JW Lim向我展示了良好的举止!
关于Python Tkinter 应用程序在 Mac OS X 上导致 fork()/exec() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21143866/
我正在尝试设置 rbenv: https://github.com/sstephenson/rbenv#section_2 我有一个问题:我必须在一切之前使用 rbenv exec 所以现在我要做 b
我已经使用我们的应用程序创建了图像,运行该图像后,我可以看到还创建了 docker 容器,当我尝试进入 docker 容器时,出现以下错误,请您在这里帮助我。 """"OCI runtime exec
这post on javapapers.com显示如何运行 JMH通过键入 mvn exec:exec 在 Maven 中进行基准测试。在 Maven 中运行 JMH 非常方便,因为您可以轻松地从 E
因为我是 shell 脚本的新手,exec命令总是让我感到困惑,同时用 while 探索这个话题循环触发了以下 4 个问题: 下面的语法 1 和 2 有什么区别 语法 1: while read LI
湖一看这两条线 案例 1 set cvsUpdStr [exec cvs -qn upd] 案例 2 set cvsUpdStr [exec cvs -qn upd >&@stdout] 对于第一种情
我有一个配置为使用 Maven 构建和运行的项目。该项目取决于平台特定的 native 库,我正在使用发现的策略 here管理这些依赖项。 本质上,特定平台的 .dll 或 .so 文件被打包到 ja
我发现 tcl exec 命令首先从标准输出返回字符串,然后是标准错误。例如,我下面的“测试脚本”按以下顺序生成消息: puts "test started" puts stderr "some no
我有 rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: cannot ex
过去 2 天我遇到了一个问题。 我正在运行一个 tcl 脚本(用于 eggdrop),该脚本在被触发时执行本地 shell 命令(子进程),如果命令成功,它会输出结果。但是,如果命令不成功,我会收到错
假设我有一个像这样的 TCL 脚本: exec ls -l 现在这将打印出当前目录的内容。我需要将该输出作为字符串并解析它。我怎么能做到这一点? 最佳答案 exec返回输出,因此只需为其设置一个变量:
我正在尝试在 PHP 中使用 GNUPLOT 绘制正弦图,但是当我使用 exec 绘制该图时出现此错误: Warning: exec() [function.exec]: Cannot execute
我正在尝试 mvn exec:exec (或 mvn exec:java )使用类路径中的本地 jar 运行我的程序。但是 jar 无法加载: Exception in thread "main" j
我在最新的 Docker CLI 文档中注意到 Docker CLI 命令列表已经扩展。 如果我使用 码头执行 早些时候在容器内启动可执行文件现在我也可以使用 docker 容器执行 命令。 dock
这个问题在这里已经有了答案: Call to a member function exec() on a non-object error in PHP [duplicate] (1 个回答) 关闭
手册页说“exec() 系列函数用新的过程镜像替换当前的过程镜像。”但我不太明白“用新过程图像替换当前过程图像”的含义。比如exec成功,perror就达不到 execl("/bin/ls", /*
手册页说“exec() 系列函数用新的过程镜像替换当前的过程镜像。”但我不太明白“用新过程图像替换当前过程图像”的含义。比如exec成功,perror就达不到 execl("/bin/ls", /*
我正在 UrbanCode Deploy Shell 步骤中执行以下命令。我想要的是针对找到的所有文件运行 Util.sh。 find . -type f -exec ls -al {} \; fin
仅当将“-p”添加到 org.codehaus.mojo:exec-maven-plugin:1.6.0:exec 插件时,以下 pom.xml 执行才会失败,删除此参数后它运行正常,但我需要争论,有
我正在尝试进入 Maven 并开始编写一个小型库。作为库代码的一部分,我想要一个小型演示 Java 应用程序,可以用来查看库在做什么以及如何使用它。现在真正让我烦恼的一件事是,为了执行该演示,我必须执
我是 maven 的新手,在通过 maven 运行类文件时遇到问题 它运行良好 mvn exec:java -Dexec.mainClass="com.test.Test" 但不是 mvn exec:
我是一名优秀的程序员,十分优秀!