Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
Multithreading 如何使用多进程或多线程客户端在python中获得工作进度条?_Multithreading_Python 2.7_Multiprocessing_Progress Bar_Pygobject - Fatal编程技术网

Multithreading 如何使用多进程或多线程客户端在python中获得工作进度条?

Multithreading 如何使用多进程或多线程客户端在python中获得工作进度条?,multithreading,python-2.7,multiprocessing,progress-bar,pygobject,Multithreading,Python 2.7,Multiprocessing,Progress Bar,Pygobject,这是基本的想法 在阅读python文档中的所有这些内容时,我无法理解它们。它实在太多了,无法理解 有人能告诉我如何使用多线程(或多进程)客户端获取工作进度条吗? 或者是否有其他方法可以在不锁定程序GUI的情况下“更新”进度条? 我也读过一些关于这些类型的客户机试图同时访问文件时的“I/O”错误的内容&当应用程序不能正确调用多线程库时的X-server错误如何避免它们? 这次我没有写代码,我不想以一个僵尸进程或类似的东西结束(然后强迫电脑关机,我讨厌破坏宝贵的数据…)。我需要先了解我在做什么 下面

这是基本的想法

在阅读python文档中的所有这些内容时,我无法理解它们。它实在太多了,无法理解

有人能告诉我如何使用多线程(或多进程)客户端获取工作进度条吗?

或者是否有其他方法可以在不锁定程序GUI的情况下“更新”进度条?

我也读过一些关于这些类型的客户机试图同时访问文件时的“I/O”错误的内容&当应用程序不能正确调用多线程库时的X-server错误如何避免它们?


这次我没有写代码,我不想以一个僵尸进程或类似的东西结束(然后强迫电脑关机,我讨厌破坏宝贵的数据…)。我需要先了解我在做什么

下面类似的内容可能会让您开始我试着尽可能多地注释来解释这个过程

from Tkinter import *
from Queue import Queue
import ttk, threading
import time

queue = Queue()
root = Tk()

# Function to do 'stuff' and place object in queue for later #
def foo():
    # sleep to demonstrate thread doing work #
    time.sleep(5)
    obj = [x for x in range(0,10)]
    queue.put(obj)

# Create thread object, targeting function to do 'stuff' #
thread1 = threading.Thread(target=foo, args=())

# Function to check state of thread1 and to update progressbar #
def progress(thread, queue):
    # starts thread #
    thread.start()

    # defines indeterminate progress bar (used while thread is alive) #
    pb1 = ttk.Progressbar(root, orient='horizontal', mode='indeterminate')

    # defines determinate progress bar (used when thread is dead) #
    pb2 = ttk.Progressbar(root, orient='horizontal', mode='determinate')
    pb2['value'] = 100

    # places and starts progress bar #
    pb1.pack()
    pb1.start()

    # checks whether thread is alive #
    while thread.is_alive():
        root.update()
        pass

    # once thread is no longer active, remove pb1 and place the '100%' progress bar #
    pb1.destroy()
    pb2.pack()

    # retrieves object from queue #
    work = queue.get()
    return work

work = progress(thread1, queue)
root.mainloop()

希望这有帮助。让我知道你的想法

您好,我最近使用Tkinter、ttk和线程模块实现了类似的功能。。。。当我运行一个函数通过线程模块查询数据库时,我的GUI窗口中有一个移动的不确定进度条。GUI不会锁定。这听起来和你的问题类似吗?听起来很相似,但是你在使用Tkinter,而我在尝试使用PyGobject&Glade,但是,它看起来很有用。你能告诉我怎么做吗?也许是一些代码什么的?耶!终于有人来帮忙了!谢谢我最近忙着做一些杂事。事实上,这是我3天来第一次如此开放。谢谢,我会试着修改你的答案以适合我的项目。谢谢(你是第一个在我的帖子中回答问题(不是评论)的人)很乐意帮忙标记为最佳答案并向上投票?:我还在试着用这段代码做点什么。别担心。如果我能达到我的目的,我会去做的。不过,我仍在自己努力。这个例子值得大家喜爱。针对其他用例进行调优的良好指导。