- 论坛徽章:
- 0
|
本帖最后由 askandstudy 于 2012-02-20 12:24 编辑
程序在运行中不能把窗口调得太小,不然会报段错误的,然后就乱了。也试了用删除行的方法,但是效果不怎么好,后面一行下面开始有时会乱掉,调一下窗口就恢复了,可能是我没处理好。- #!/usr/bin/python
- #coding:utf-8
- import curses, sys
- import time,random
- import threading
- def workthread(stdscr,thno):
- speed=random.randint(100,200)/100.0
- testnumber=2
- for i in range(testnumber):
- curprogress=0
- while (curprogress+speed*5)<100:
- curprogress += speed*5
- info='thread [%02d] is downloading... [%02d%%] ' % (thno,curprogress)
- updateprogress(stdscr,thno,info)
- time.sleep(0.5)
- curprogress=100
- info='thread [%02d] is downloading... [%02d%%] ' % (thno,curprogress)
- updateprogress(stdscr,thno,info)
- def updateprogress(stdscr,line,info):
- stdscr.move(line,0)
- stdscr.addstr(line,0,info)
- stdscr.refresh()
- return 0
- def main(stdscr):
- stdscr.clear()
- stdscr.refresh()
- #start thread
- threads={}
- threadnumbers=5
- for i in range(threadnumbers):
- th=threading.Thread(target=workthread,name='thread%d' % i,args=(stdscr,i))
- th.start()
- thid=str(th.ident)
- threads[thid]=th
- while 1:
- thidnume=[str(x.ident) for x in threading.enumerate()]
- for key,value in threads.items():
- if key not in thidnume:
- threads.pop(key)
- if len(threads)<=0:
- break
- time.sleep(1)
- return 0
- curses.wrapper(main)
复制代码 感觉用后面加空格来覆盖前面的输出的方法也还行啊。
要做得好一些似乎还是需要花些功夫的,线程结束就删除改行等功能似乎还是需要用到删除行的处理。
|
|