Python线程池代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
这里,我使用的官网的progressbar组件,打算在多线程中进行使用。
主要方法和属性如下:
- currval: current value of the progress, 0 <= currval <= maxval
- maxval: maximum (and final) value of the progress
- finished: True if the bar is have finished (reached 100%), False o/w
- start_time: first time update() method of ProgressBar was called
- seconds_elapsed: seconds elapsed since start_time
- percentage(): percentage of the progress (this is a method)
我打算在wait_allcomplete()函数中进行修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
主要思路就是:当有一个线程退出的时候就更新下进度条,但执行的时候,以上代码没能达到预期。
希望大家帮忙看下问题出在哪里
迷茫2017-04-17 13:30:24
Queue中有个属性:unfinished_tasks
,存储了当前未完成的任务数量。
每完成一个任务(task_done
),unfinished_tasks
的值就会减一。
具体可以查看Queue中的task_done函数。
另外,已经有人将线程池和进度条结合起来了,具体请看starcluster.threadpool
重点看ThreadPool类中的wait函数。
这篇文章你也可以了解下:Queue里task_done方法使用注意