ChinaUnix.net
相关文章推荐:

python32 多线程

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线程编程里,如何设置子线程的超时时间,就是子线程超时了自动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)

下面的代码,运行一段时间就报错,无法创建新的线程,还请高手指点一下。[code]import socket ,threading ip=('192.168.1.20') def abc(ip,post): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(1) try: sk.connect((ip,post)) print 'Server port %d OK!'%(post) except Exception: pass #print 'Server port %d not connect!'%(post) sk.close(...

by kaixindehuan - Python - 2013-06-24 16:44:48 阅读(1108) 回复(4)

python 线程读取数据库 [code] from mysql import MYSQL import threading zzzzz = [] def run(z,zz): SQL = "select * from e_verify_email where Id = \'"+zz+"\'" my = MYSQL(SQL) alldata = my.getRs() zzzzz.append(alldata) if __name__ == "__main__": threads = [] k = 5 for a in range(0,k): z = threading.Thread(target=run,args=(a,str(a+1...

python

by 中关村村草 - Python - 2011-09-13 12:55:13 阅读(5508) 回复(6)

[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)

一个简单的测试,两个线程,在线程中打印日志,日志打印到文件中,发现线程无法打印日志。 thread1.py代码如下:[code]import logger.log import threading import t log = logger.log.Logger.getLogger(__name__) def thread1(): t.test('1') def thread2(): t.test('2') if __name__ == '__main__': log.debug('start main') t1 = threading.Timer(10.0, thread1) t1.start() t2 = threading.Tim...

by whyliyi - Python - 2014-10-04 11:11:01 阅读(3707) 回复(12)

本帖最后由 SeriousCool 于 2013-12-08 18:35 编辑 python语言: python实现线程下载 #!/usr/bin/python # -*- coding: utf-8 -*- # filename: paxel.py '''It is a multi-thread downloading tool It was developed follow axel. Author: volans E-mail: volansw [at] gmail.com ''' import sys import os import time import urllib from threading import Thread local_proxies = {'http': 'http:/...

by SeriousCool - Python - 2013-12-08 18:34:57 阅读(997) 回复(0)

本帖最后由 tank064 于 2013-11-20 18:04 编辑 hello 最近在倒腾一个可以post提交用户名密码的下载脚本, 在网上搜索了下,找到不少相关文章. 下面是一段代码[code]class Axelpython(Thread, urllib.FancyURLopener): '''Multi-thread downloading class. run() is a vitural method of Thread. ''' def __init__(self, threadname, url, filename, ranges=0, proxies={}): Thread.__init__(self, ...

by tank064 - Python - 2013-11-22 00:52:27 阅读(3865) 回复(9)