# coding:utf-8
import socket
import threading
import time
EOL1 = '\n\n'
EOL2 = '\n\r\n'
body = '''Hello, world! <h1> from earth </h1> - from {thread_name}'''
response_params = [
'HTTP/1.0 200 OK',
'Date: Sat, 10 jun 2019 01:01:01 GMT',
'Content-Type: text/plain; charset=utf-8',
'Content-Length: {length}\r\n',
body,
]
response = b'\r\n'.join(response_params)
def handle_connection(conn, addr):
request = ""
while EOL1 not in request and EOL2 not in request:
request += conn.recv(1024)
# print(request)
current_thread = threading.currentThread()
content_length = len(body.format(thread_name=current_thread.name))
print(current_thread.name, '-------', 'sleep 10', int(time.time()))
time.sleep(10)
conn.send(response.format(thread_name=current_thread.name, len
多线程
最新推荐文章于 2024-03-09 14:19:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)