python socket select timeout example
본 포스트는 python socket에서 리눅스의 select와 동일한 기능을 하는 select 모듈 사용 예제를 싣고 있다. 이전 포스트에서 non-blocking socket 프로그래밍에 대해 알아봤었다. 아래 링크의 포스트에서 만들어진 예제에 'select' 모듈을 추가해 예제 코드를 만들었다. python socket API 와 non-blocking socket server client example code 1. python socket select timeout example 이전 포스트의 클라이언트 코드에서 select를 사용하지 않은 코드는 아래와 같다. import socket import time def recv(sock,size,timeout_ms): while timeout_ms > 0: try: data = sock.recv(size) if data is not None: return data.decode() except BlockingIOError: timeout_ms -= 1 time.sleep(0.001) return None 위 코드를 수정해 select를 사용하면 아래와 같이 구현...