ChinaUnix.net
相关文章推荐:

python多线程中run的作用

[code] import threading,urllib def openurl(): while 1: url = urllib.urlopen('http://domain.com') if __name__=='__main__': for i in range(100): i = threading.Thread(target = openurl) i.start() [/code] 写着玩的.

by tmdxy - Python - 2005-06-06 10:07:31 阅读(7017) 回复(0)

相关讨论

最近学习python线,有一个初学例子搞得不太清除:[code]import thread i = 11 def doit(ind): global i mutex.acquire() temp = 1 i = temp + 1 print "i=%d" % i mutex.release() mutex=thread.allocate_lock() for ind in range(10): thread.start_new(doit,(ind,)) raw_input()[/code]python版本:2.6.2 因为有thread lock,例子的原文说会输出从2,3,4 。。。。直到11. 但是我运行了以后并不是这样:[co...

by rootsoso - Python - 2010-06-01 19:40:34 阅读(4286) 回复(4)

python的并行开发有两种方式:fork和thread(线)。thread比fork更轻量级,具有更好运行效率和可移植性,在需要进行并行操作的场合首推thread。 python标准库内置一个thread模块,该模块提供一个轻便简易的线接口,可以无需任何修改就能够运行在Win、Solaris、Linux等操作系统上。浏览一下thread模块: import thread dir(thread) 看到 ['LockType', '__doc__', '__name__', '_local', 'allocate', 'allocate_lock', 'e...

by tessykandy - Python文档中心 - 2009-03-23 13:48:49 阅读(1601) 回复(0)

现有几个小序(5,6)个,更能各不相同。想使用线来控制这几个小序。 达到:能够定时运行这个几个小序。 但对线不太了解,清大虾给些指点。。。

by blamos - Python - 2008-11-07 11:27:09 阅读(2201) 回复(6)

线总是会有点迷糊,那位高手给小弟指点一下?谢。

by pyll - Python - 2008-10-17 21:15:29 阅读(1731) 回复(1)

python线(一)线对象 :感觉篇文章写得挺有意思的哦!转载一起分享 我们在做软件开发的时候很要用到线技术。例如如果做一个下载软件象flashget就要用到、象在线视频工具realplayer也要用到因为要同时下载media stream还要播放。其实例子是很的。 线相对进来说是“轻量级”的,操作系统用较少的资源创建和管理线线在相同的内存空间执行,并共享许相同的资源。 在[color="#99cc00"]python如...

by hkebao - Python文档中心 - 2009-01-20 11:00:31 阅读(2322) 回复(0)

# -*- coding: utf-8 -*- import os,sys,time,re from threading import Thread class DownloadWeather(Thread): def __init__(self, path, url, num_of_workers=5, timeout = 2): Thread.__init__(self) self.path = path self.url = url #self.city = city def run(self): #use command "curl" download data from sina.com.cn os.popen("/usr/local/bin/cu...

by mageguoshi - Python文档中心 - 2008-03-05 14:01:04 阅读(1620) 回复(0)

大家好: 请问在python线里,如何设置子线的超时时间,就是子线超时了自动kill,有没有这样的方法?谢谢

by horizonhyg - Python - 2013-06-28 17:54:01 阅读(3582) 回复(4)

看下这段代码,pygame写的一个循环播放背景音乐:[code]#-*- coding: utf-8 -*- #file:test.py # import threading import pygame pygame.mixer.init() class player(threading.Thread): def __init__(self,song_path,end_flag): threading.Thread.__init__(self) self.end_flag = end_flag self.song_path = song_path def run(self): pygame.mixer.music.load(self.song_path) ...

by theredghost - Python - 2012-06-18 10:53:07 阅读(1197) 回复(2)

python编码我们经常讨论的一个方面就是如何优化模拟执行的性能。尽管在考虑量化代码时NumPy、SciPy和pandas在这方面已然非常有用,但在构建事件驱动系统时我们无法有效地使用这些工具。有没有可以加速我们代码的其他办法?答案是肯定的,但需要留意! 在这篇文章,我们看一种不同的模型-并发,我们可以将它引入我们python。这种模型在模拟工作地特别好,它不需要共享状态。Monte Carlo模拟器可以用来做期权定价以及...

by Patagonia - IT资讯 - 2014-05-08 15:03:09 阅读(1261) 回复(2)

本帖最后由 Gray1982 于 2012-02-02 14:11 编辑 所需软件: python2.7.tar.bz2 paramiko-1.7.7.1.tar.gz pycrypto-2.3.tar.gz 所需文件内容格式为: IP,sshPort,Username,Password 执行: python2.7 脚本名 有些朋友可以考虑到密码明文的问题,目前这个版本没设置任何加密因为目前还不需要。不过密码安全不是问题,最简单的例子,我的密码是6位,现在给出一串字符72d88491c45b43e6fde7bceeaf6,在这里,你能知道那...

by Gray1982 - Python - 2015-03-18 11:03:24 阅读(6401) 回复(18)