基本上我只想知道我是否为并发套接字线程正确实现了线程。这是我的方法:
#!/usr/bin/env python
import sys
import time
from gevent import socket, Timeout, select
from gevent.pool import Pool
def worker(website):
data = str()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.connect(('google.com',80))
s.send('HEAD / HTTP/1.1\n\n')
while True:
read, w, e = select.select([s], [], [])
if read:
data = s.recv(1024)
if data:
break
print ('done')
return 0
def main():
pool = Pool(10)
for item in items:
pool.spawn(worker, item)
pool.join()