Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python多线程工作负载崩溃 #/usr/bin/env python #-*-编码:utf-8-*- # #无标题3.py # #版权所有2015 Ognjen Galic # #这个程序是自由软件;您可以重新分发和/或修改它 #它是根据GNU通用公共许可证的条款发布的 自由软件基金会;许可证的第2版,或 #(由您选择)任何更高版本。 # #这个节目的发布是希望它会有用, #但无任何保证;甚至没有任何关于 #适销性或适合某一特定目的。见 #有关更多详细信息,请参阅GNU通用公共许可证。 # #您应该已经收到GNU通用公共许可证的副本 #与此同时,;如果没有,请写信给自由软件 波士顿基金会51楼富兰克林街第五楼 #MA 02110-1301,美国。 # # 导入命令 导入线程 从ui导入ui\u主窗口 从PyQt4导入QtGui、QtCore 从时间上导入睡眠 导入系统 类主窗口(QtGui.QMainWindow、Ui\u主窗口): 定义初始化(自): 超级(主窗口,自我)。\uuuu初始化 self.setupUi(self) def do_sudo(命令): #使用命令执行任务() def ui(): app=QtGui.QApplication(sys.argv) ui.main窗口() ui.show() def main(): ui=主窗口() 对于范围(1100)内的i: ui.progressBar.setValue(i) 睡眠(1) 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': threading.Thread(target=ui.start()) threading.Thread(target=main).start()_Python_Multithreading_Python Multithreading - Fatal编程技术网

Python多线程工作负载崩溃 #/usr/bin/env python #-*-编码:utf-8-*- # #无标题3.py # #版权所有2015 Ognjen Galic # #这个程序是自由软件;您可以重新分发和/或修改它 #它是根据GNU通用公共许可证的条款发布的 自由软件基金会;许可证的第2版,或 #(由您选择)任何更高版本。 # #这个节目的发布是希望它会有用, #但无任何保证;甚至没有任何关于 #适销性或适合某一特定目的。见 #有关更多详细信息,请参阅GNU通用公共许可证。 # #您应该已经收到GNU通用公共许可证的副本 #与此同时,;如果没有,请写信给自由软件 波士顿基金会51楼富兰克林街第五楼 #MA 02110-1301,美国。 # # 导入命令 导入线程 从ui导入ui\u主窗口 从PyQt4导入QtGui、QtCore 从时间上导入睡眠 导入系统 类主窗口(QtGui.QMainWindow、Ui\u主窗口): 定义初始化(自): 超级(主窗口,自我)。\uuuu初始化 self.setupUi(self) def do_sudo(命令): #使用命令执行任务() def ui(): app=QtGui.QApplication(sys.argv) ui.main窗口() ui.show() def main(): ui=主窗口() 对于范围(1100)内的i: ui.progressBar.setValue(i) 睡眠(1) 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': threading.Thread(target=ui.start()) threading.Thread(target=main).start()

Python多线程工作负载崩溃 #/usr/bin/env python #-*-编码:utf-8-*- # #无标题3.py # #版权所有2015 Ognjen Galic # #这个程序是自由软件;您可以重新分发和/或修改它 #它是根据GNU通用公共许可证的条款发布的 自由软件基金会;许可证的第2版,或 #(由您选择)任何更高版本。 # #这个节目的发布是希望它会有用, #但无任何保证;甚至没有任何关于 #适销性或适合某一特定目的。见 #有关更多详细信息,请参阅GNU通用公共许可证。 # #您应该已经收到GNU通用公共许可证的副本 #与此同时,;如果没有,请写信给自由软件 波士顿基金会51楼富兰克林街第五楼 #MA 02110-1301,美国。 # # 导入命令 导入线程 从ui导入ui\u主窗口 从PyQt4导入QtGui、QtCore 从时间上导入睡眠 导入系统 类主窗口(QtGui.QMainWindow、Ui\u主窗口): 定义初始化(自): 超级(主窗口,自我)。\uuuu初始化 self.setupUi(self) def do_sudo(命令): #使用命令执行任务() def ui(): app=QtGui.QApplication(sys.argv) ui.main窗口() ui.show() def main(): ui=主窗口() 对于范围(1100)内的i: ui.progressBar.setValue(i) 睡眠(1) 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': threading.Thread(target=ui.start()) threading.Thread(target=main).start(),python,multithreading,python-multithreading,Python,Multithreading,Python Multithreading,这是为什么 我需要让UI在运行commands()的同时进行刷新,并在更新UI的同时进行更新 为了测试它,我设置了一个小型for循环 但它会在运行时立即抛出和分段错误,代码为139。尝试在创建线程后添加while True循环: #!/usr/bin/env python # -*- coding: utf-8 -*- # # untitled3.py # # Copyright 2015 Ognjen Galic <gala@thinkpad> # # This pr

这是为什么

我需要让UI在运行commands()的同时进行刷新,并在更新UI的同时进行更新

为了测试它,我设置了一个小型for循环


但它会在运行时立即抛出和分段错误,代码为139。

尝试在创建线程后添加while True循环:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  untitled3.py
#  
#  Copyright 2015 Ognjen Galic <gala@thinkpad>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

import commands
import threading
from ui import Ui_main_window
from PyQt4 import QtGui, QtCore
from time import sleep
import sys

class MainWindow(QtGui.QMainWindow, Ui_main_window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

def do_sudo(command):
    # do stuffs with commands()

def ui():
    app = QtGui.QApplication(sys.argv)
    ui.MainWindow()
    ui.show()

def main():
    ui = MainWindow()
    for i in range(1,100):
            ui.progressBar.setValue(i)
            sleep(1)

if __name__ == '__main__':
    threading.Thread(target = ui).start()
    threading.Thread(target = main).start()

尝试在创建线程后添加while True循环:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  untitled3.py
#  
#  Copyright 2015 Ognjen Galic <gala@thinkpad>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

import commands
import threading
from ui import Ui_main_window
from PyQt4 import QtGui, QtCore
from time import sleep
import sys

class MainWindow(QtGui.QMainWindow, Ui_main_window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

def do_sudo(command):
    # do stuffs with commands()

def ui():
    app = QtGui.QApplication(sys.argv)
    ui.MainWindow()
    ui.show()

def main():
    ui = MainWindow()
    for i in range(1,100):
            ui.progressBar.setValue(i)
            sleep(1)

if __name__ == '__main__':
    threading.Thread(target = ui).start()
    threading.Thread(target = main).start()

启动线程后,程序不会等待线程运行。尝试在创建线程后添加一个while True:time.sleep(1.0)。成功了!多线程新手,不知道!发布我的投票答案!如果name='main':threading.Thread(target=ui).start()sleep(1)threading.Thread(target=main).start()sleep(1)启动线程后,程序不会等待线程运行。尝试在创建线程后添加一个while True:time.sleep(1.0)。成功了!多线程新手,不知道!发布我的投票答案!如果name='main':threading.Thread(target=ui).start()sleep(1)threading.Thread(target=main).start()sleep(1)