Python: RAII:函数执行完毕,socket对象主动发送fin
第一次知道python的这个默认RAII的功能。函数内的举报socket变量,在函数退出的时候,主动发fin。
import socket
import threading
import timedef create_connection():s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect(('169.254.218.0', 5070))s.send(b"Hello")#print("create one")for i in range(1000000):create_connection()#print("create one ")
time.sleep(50)