English 中文(简体)
页: 1
原标题:Python sock.listen(...)

登峰造物文件上所见sock.listen(5)的所有例子都表明,我应当确定最大积压号为5<>。 这对我来说是一个问题,因为我期望的是数量很多(同时连接很多)。 我把它定在200处,没有看到我的系统存在任何问题,但我想知道,我怎么能把这个问题摆在面前。

谁知道?

Edit: 这里我接受()休息。

while True:    
    try:
        self.q.put(sock.accept())
    except KeyboardInterrupt:
        break
    except Exception, e:
        self.log("ERR %s" % e)
最佳回答

话语

socket.listen(backlog) Listen for connections made to the socket. The backlog argument specifies the maximum number of queued connections and should be at least 1; the maximum value is system-dependent (usually 5).

显然,你的系统价值超过了5。 我看不出为什么把这个问题摆在更多的位置。 也许每个被问到的连接都保留了记忆。

我的气球手页必须这样说。

If the backlog argument is greater than the value in /proc/sys/net/core/somaxconn, then it is silently truncated to that value; the default value in this file is 128. In kernels before 2.4.25, this limit was a hard coded value, SOMAXCONN, with the value 128.

问题回答

您不需要将参数调整到<代码>listen()以超过5。

参数控制了允许多少个非<代码>accept(>-ed链接被排除在外。 <>编码>(<>>>参数>与同时连接的袖珍数量没有关系,仅与未成为<代码>accept(<>的并行链接数有关。

如果将参数调整到<代码>listen(>>)对您的代码产生影响,即每打到accept(之间发生太多延误。 然后,你想改变<条码>accept(>>,从而减少间接费用。

在您的案例中,我猜测: Self.q is a python queue,在这种情况下,你可能要打电话,以避免出现blocking<><>>>> www.un.org/Depts/DGACM/index_french.htm

采用<代码>backlog <>/code>作为缺省参数,可将其空出:

如果未指定,则选择默认的合理值。从版本3.5开始更改:backlog参数现在是可选的。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签