1 Star 0 Fork 46

zhaoshucai/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.1.15 multiprocess-server-signal 830 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-01-15 10:33 . new file
import os, time, sys, signal
from socket import *
from multiprocessing import Process
myHost = ''
myPort = 50007
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((myHost, myPort))
sockobj.listen(5)
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
def now():
return time.ctime(time.time())
def handleClient(connection):
print('Child:', os.getpid())
time.sleep(5)
while True:
data = connection.recv(1024)
if not data: break
reply = 'Echo=>%s at %s' % (data, now())
connection.send(reply.encode())
connection.close()
os._exit(0)
def dispatcher():
while True:
connection, address = sockobj.accept()
print('Server connected by', address, end = ' ')
print('at', now())
Process(target = handleClient, args = (connection,)).start()
if __name__ == '__main__':
dispatcher()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zhaoshucai/qytang_Python.git
git@gitee.com:zhaoshucai/qytang_Python.git
zhaoshucai
qytang_Python
qytang_Python
master

搜索帮助