【问题标题】:Facing error : OSError: [Errno 98] Address already in use: ('', 8089)面临错误:OSError:[Errno 98] 地址已在使用中:('',8089)
【发布时间】:2020-10-13 07:03:35
【问题描述】:

我正在尝试运行 locust,在第一次成功运行后,我对 locustfile.py 做了一些更改。运行 locust 命令后出现错误“OSError: [Errno 98] Address already in use: ('', 8089)”。已经尝试杀死PID,但它不起作用。我使用的是 Linux 18.04 系统。 共享完整的日志跟踪:

[2020-06-23 14:22:25,687] sonali-Latitude-3490/WARNING/locust.main: System open file limit setting is not high enough for load testing, and the OS wouldnt allow locust to increase it by itself. See https://docs.locust.io/en/stable/installation.html#increasing-maximum-number-of-open-files-limit for more info.
[2020-06-23 14:22:25,687] sonali-Latitude-3490/INFO/locust.main: Starting web interface at http://:8089
[2020-06-23 14:22:25,694] sonali-Latitude-3490/INFO/locust.main: Starting Locust 1.0.3
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "/home/sonali/.local/lib/python3.6/site-packages/locust/web.py", line 288, in start
    self.server.serve_forever()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/baseserver.py", line 398, in serve_forever
    self.start()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/baseserver.py", line 336, in start
    self.init_socket()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/pywsgi.py", line 1500, in init_socket
    StreamServer.init_socket(self)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 180, in init_socket
    self.socket = self.get_listener(self.address, self.backlog, self.family)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 192, in get_listener
    return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 288, in _tcp_listener
    sock.bind(address)
OSError: [Errno 98] Address already in use: ('', 8089)
2020-06-23T08:52:25Z <Greenlet at 0x7fcb12f1f148: <bound method WebUI.start of <locust.web.WebUI object at 0x7fcb12ef2668>>> failed with OSError

[2020-06-23 14:22:25,696] sonali-Latitude-3490/CRITICAL/locust.web: Unhandled exception in greenlet: <Greenlet at 0x7fcb12f1f148: <bound method WebUI.start of <locust.web.WebUI object at 0x7fcb12ef2668>>>
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "/home/sonali/.local/lib/python3.6/site-packages/locust/web.py", line 288, in start
    self.server.serve_forever()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/baseserver.py", line 398, in serve_forever
    self.start()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/baseserver.py", line 336, in start
    self.init_socket()
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/pywsgi.py", line 1500, in init_socket
    StreamServer.init_socket(self)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 180, in init_socket
    self.socket = self.get_listener(self.address, self.backlog, self.family)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 192, in get_listener
    return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family)
  File "/home/sonali/.local/lib/python3.6/site-packages/gevent/server.py", line 288, in _tcp_listener
    sock.bind(address)
OSError: [Errno 98] Address already in use: ('', 8089)
[2020-06-23 14:22:25,696] sonali-Latitude-3490/INFO/locust.main: Running teardowns...
[2020-06-23 14:22:25,696] sonali-Latitude-3490/INFO/locust.main: Shutting down (exit code 2), bye.
[2020-06-23 14:22:25,696] sonali-Latitude-3490/INFO/locust.main: Cleaning up runner...
 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                         0     0(0.00%)       0       0       0  |       0    0.00    0.00

Percentage of the requests completed within given times
 Type                 Name                                                           # reqs    50%    66%    75%    80%    90%    95%    98%    99%  99.9% 99.99%   100%
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------

【问题讨论】:

  • 其他东西,可能是其他蝗虫实例,已经在该端口上运行。
  • 是的,@KlausD。我用命令 kill -9 杀死了 PID,它现在正在工作。

标签: python server locust oserror


【解决方案1】:

如果我没记错的话……

默认情况下,套接字不会立即关闭。内核处理了一个“温和”时期,它与 SO_LINGER 值相关联。参见例如http://deepix.github.io/2016/10/21/tcprst.html

这意味着在您的服务器套接字再次可用之前,您需要“稍等一下”。

https://www.programcreek.com/python/example/67443/socket.SO_LINGER 中给出了如何在 python 中处理此问题的示例。

【讨论】:

  • 感谢您提供更多信息!!,我将尝试实现它现在,我能够通过命令kill -9 &lt;PID&gt; 杀死 PID
猜你喜欢
  • 2021-05-14
  • 2020-05-18
  • 1970-01-01
  • 2022-06-26
  • 2015-06-04
  • 2021-05-10
  • 2022-01-18
  • 1970-01-01
  • 2011-05-26
相关资源
最近更新 更多