python socket server 并发(转)
import SocketServer, time, select, sys
from threading import Thread
COMMAND_HELLO = 1
COMMAND_QUIT = 2
# The SimpleRequestHandler class uses this to parse command lines.
class SimpleCommandProcessor:
def __init__(self):
pass
def process(self, line, request):
"""Process a command"""
args = line.split(' ')
command = args[0].lower()
args = args[1:]
if command == 'hello':
request.send('HELLO TO YOU TO!\n\r')
return COMMAND_HELLO
elif command == 'quit':
request.send('OK, SEE YOU LATER\n\r')
return COMMAND_QUIT
else:
request.send('Unknown command: "%s"\n\r' % command)
# SimpleServer extends the TCPServer, using the threading mix in
# to create a new thread for every request.
class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
# This means the main server will not do the equivalent of a
# pthread_join() on the new threads. With this set, Ctrl-C will
# kill the server reliably.
daemon_threads = True
# By setting this we allow the server to re-bind to the address by
# setting SO_REUSEADDR, meaning you don't have to wait for
# timeouts when you kill the server and the sockets don't get
 
相关文档:
使用pdb调试Python程序
本文讨论在没有方便的IDE工具可用的情况下,使用pdb调试python程序
源码例子
例如,有模拟税收计算的程序:
#!/usr/bin/python
def debug_demo(val):
if val &l ......
from http://blog.alexa-pro.cn/?p=315
此文档使用平台为 cPAMIE Build 2.0,和之前的版本有明显的差别,具体可直接看cPAMIE.py 源码
下面是一些常用的方法
ie.navigate('http://blog.alexa.cn') 用来访问一个链接。
ie.linkClick('linkname') 打开这个页面中的一个连接 参数: name或 id
ie.textBoxSet('labels','python ......
server:
import sys
import socket
host = sys.argv[1]
port = int(sys.argv[2])
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host,port))
while 1:
try:
&n ......
from link http://www.tt010.net/cms/show_article/1057.html
发表评论
Post by : BossAdmin @[2009-12-12 17:11:20] views:115
adodb:我们领导推荐的数据库连接组件
bsddb3:BerkeleyDB的连接组件
Cheetah-1.0:我比较喜欢这个版本的cheetah
cherrypy:一个WEB framework
ctypes:用来调用动态链接库
DBUtils:数 ......
from link http://www.tt010.net/cms/show_article/1057.html
发表评论
Post by : BossAdmin @[2009-12-12 17:11:20] views:115
adodb:我们领导推荐的数据库连接组件
bsddb3:BerkeleyDB的连接组件
Cheetah-1.0:我比较喜欢这个版本的cheetah
cherrypy:一个WEB framework
ctypes:用来调用动态链接库
DBUtils:数 ......