Python的线程

Python的参数传递其实传递的是对象,当传递可变对象(列表、队列)时相当于引用传递,可以修改对象的原始值,当传递不可变对象(字符串、整型)时就相当于传值,不能直接修改原始对象。 0x00 单线程 #!/usr/bin/env python # -*- coding: utf-8 -*- from time import time,ctime,sleep def music(arg): for x in range(2): print "I'm listening to %s. %s" % (arg,ctime()) sleep(1) def movie(arg): for x in range(2): print "I'm watching %s. %s" % (arg,ctime()) sleep(5) if __name__ == '__main__': start = int(time()) music(u'我') movie(u'可是') print "All over time:%s" % ctime() print "Used time:%d" % int(time()-start) 0x01 多线程 #!/usr/bin/env python # -*- coding: utf-8 -*- import re import requests import threading from time import time,ctime,sleep INDEX = 0 def http_get(sites): global INDEX while INDEX < len(sites): url = sites[INDEX] INDEX += 1 resp = requests.



可以返回顶部