【发布时间】:2012-11-19 05:14:58
【问题描述】:
我是 python 新手,遇到一个奇怪的错误:
Segmentation fault (core dumped)
当我执行以下代码时:
class Workspace(QMainWindow, Ui_MainWindow):
""" This class is for managing the whole GUI `Workspace'.
Currently a Workspace is similar to a MainWindow
"""
def __init__(self):
#p= subprocess.Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/', shell=True, stdout=subprocess.PIPE, bufsize= 4024)
try:
from Queue import Queue, Empty
except ImportError:
while True:
#from queue import Queue, Empty # python 3.x
print "error"
ON_POSIX = 'posix' in sys.builtin_module_names
def enqueue_output(out, queue):
for line in iter(out.readline, b''):
queue.put(line)
out.close()
p= Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/',stdout=PIPE, shell=True, bufsize= 4024)
q = Queue()
t = threading.Thread(target=enqueue_output, args=(p.stdout, q))
#t = Thread(target=enqueue_output, args=(p.stdout, q))
t.daemon = True # thread dies with the program
t.start()
# ... do other things here
def myfunc(q):
while True:
try: line = q.get_nowait()
# or q.get(timeout=.1)
except Empty:
print('Vacio')
else: # got line
# ... do something with line
print line
thread = threading.Thread(target=myfunc, args=(q,))
thread.start()
这部分代码是从程序的标准输出中读取的。当我在线程外执行myfunc 时它可以工作!但是当我在线程fais中执行它时......
有什么建议吗?
【问题讨论】:
-
上面代码中的
q是什么? -
@JasonSperske:是的,但问题是哪个——如果是
queue.Queue,可能是Python配置问题,最好的解决办法是卸载重装Python ;如果是foomodule.Queue,则很可能是foo库中的错误。 -
PS,@karensantana:什么 Python 版本,什么平台?
-
我有一个队列类:q = Queue()
标签: python