Python sock.listen(…)

前端 未结 2 1031
天命终不由人
天命终不由人 2020-12-10 06:39

All the examples I\'ve seen of sock.listen(5) in the python documentation suggest I should set the max backlog number to be 5. This is causing a pr

2条回答
  •  忘掉有多难
    2020-12-10 06:47

    You don't need to adjust the parameter to listen() to a larger number than 5.

    The parameter controls how many non-accept()-ed connections are allowed to be outstanding. The listen() parameter has no bearing on the number of concurrently connected sockets, only on the number of concurrent connections which have not been accept()-ed by the process.

    If adjusting the parameter to listen() has an impact on your code, that is a symptom that too much delay occurs between each call to accept(). You would then want to change your accept() loop such that it has less overhead.

    In your case, I am guessing that self.q is a python queue, in which case you may want to call self.q.put_nowait() to avoid any possibility of blocking the accept() loop at this call.

提交回复
热议问题