BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / www-technology / #23670同步于 2014/3/20
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖

【求助】怎样让python程序执行完成一个函数才接着执行下一个?

inthesun
2014/3/20镜像同步6 回复
说明 download_mult( download_policyno, sametime) 是自己写的多任务下载的函数,同时创建20个(这里sametime=20)执行download_policyno功能的线程。但是现在的问题是不等download_mult执行完就立即进入下一个循环了(见截图)。 请问怎样让download_mult执行完才接着执行下一个?谢谢 下面是部分python代码 ...... while (i <=max): #sys.stdout.write("The ulNum is: %u " % i) # 创建多个线程 download_mult( download_policyno, sametime) print i print time.strftime('%Y-%m-%d %A %X',time.localtime(time.time()))+'================================================' i += sametime #sys.stdout.write( "Use time: %s" % (time.clock() - time_begin)) #print "Use time: %s" % (time.clock() - time_begin) os.system("pause") ......
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
inthesun机器人#1 · 2014/3/20
哎 暂时用笨办法解决了 每次执行后等待个数秒钟、、
binux机器人#2 · 2014/3/20
join
inthesun机器人#3 · 2014/3/20
【 在 binux 的大作中提到: 】 : join join 是什么意思 库吗
binux机器人#4 · 2014/3/20
看你多线程库的文档 【 在 inthesun 的大作中提到: 】 : join 是什么意思 库吗
jessica1机器人#5 · 2014/3/22
http://docs.python.org/2.7/library/threading.html?highlight=join#threading.Thread.join Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception – or until the optional timeout occurs 举个栗子: #!/usr/bin/env python import time import threading def func(): print 'new thread' time.sleep(5) if __name__=='__main__': print 'main thread' new_thread = threading.Thread(target=func) new_thread.start() new_thread.join() #main thread will block here until child thread terminate print 'main thread' 【 在 inthesun 的大作中提到: 】 : join 是什么意思 库吗
inthesun机器人#6 · 2014/4/1
感谢ls们哈 join确实有用