Locust – AttributeError when accessing locust web interface
Question:
I’m trying to run a very basic locust load testing which did work previously.
from locust import HttpUser, between, task
class QuickstartUser(HttpUser):
wait_time = between(1, 5)
@task
def get_status(self):
self.client.get("/status/")
Running the following command: locust -f <package-name>/tests/load_tests.py -r 20 -u 400 -H http://localhost:8000
yields the following error message when trying to access the web interface:
[2022-12-28 23:23:30,962] MacBook-Pro.fritz.box/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2022-12-28 23:23:30,968] MacBook-Pro.fritz.box/INFO/locust.main: Starting Locust 2.14.0
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/baseserver.py", line 34, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 1577, in handle
handler.handle()
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 464, in handle
result = self.handle_one_request()
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 656, in handle_one_request
if self.rfile.CLOSED:
AttributeError: '_io.BufferedReader' object has no attribute 'CLOSED'
2022-12-28T22:23:35Z <Greenlet at 0x106fbc3a0: _handle_and_close_when_done(<bound method WSGIServer.handle of <WSGIServer at , <bound method StreamServer.do_close of <WSGIServer, (<gevent._socket3.socket [closed] at 0x106fcb460 o)> failed with AttributeError
The following versions are being used:
$ poetry show locust --tree
locust 2.14.0 Developer friendly load testing framework
├── configargparse >=1.0
├── flask >=2.0.0
│ ├── click >=8.0
│ │ └── colorama *
│ ├── itsdangerous >=2.0
│ ├── jinja2 >=3.0
│ │ └── markupsafe >=2.0
│ └── werkzeug >=2.2.2
│ └── markupsafe >=2.1.1 (circular dependency aborted here)
├── flask-basicauth >=0.2.0
│ └── flask *
│ ├── click >=8.0
│ │ └── colorama *
│ ├── itsdangerous >=2.0
│ ├── jinja2 >=3.0
│ │ └── markupsafe >=2.0
│ └── werkzeug >=2.2.2
│ └── markupsafe >=2.1.1 (circular dependency aborted here)
├── flask-cors >=3.0.10
│ ├── flask >=0.9
│ │ ├── click >=8.0
│ │ │ └── colorama *
│ │ ├── itsdangerous >=2.0
│ │ ├── jinja2 >=3.0
│ │ │ └── markupsafe >=2.0
│ │ └── werkzeug >=2.2.2
│ │ └── markupsafe >=2.1.1 (circular dependency aborted here)
│ └── six *
├── gevent >=20.12.1
│ ├── cffi >=1.12.2
│ │ └── pycparser *
│ ├── greenlet >=2.0.0
│ ├── setuptools *
│ ├── zope-event *
│ │ └── setuptools * (circular dependency aborted here)
│ └── zope-interface *
│ └── setuptools * (circular dependency aborted here)
├── geventhttpclient >=2.0.2
│ ├── brotli *
│ ├── certifi *
│ ├── gevent >=0.13
│ │ ├── cffi >=1.12.2
│ │ │ └── pycparser *
│ │ ├── greenlet >=2.0.0
│ │ ├── setuptools *
│ │ ├── zope-event *
│ │ │ └── setuptools * (circular dependency aborted here)
│ │ └── zope-interface *
│ │ └── setuptools * (circular dependency aborted here)
│ └── six *
├── msgpack >=0.6.2
├── psutil >=5.6.7
├── pywin32 *
├── pyzmq >=22.2.1,<23.0.0 || >23.0.0
│ ├── cffi *
│ │ └── pycparser *
│ └── py *
├── requests >=2.23.0
│ ├── certifi >=2017.4.17
│ ├── charset-normalizer >=2,<3
│ ├── idna >=2.5,<4
│ └── urllib3 >=1.21.1,<1.27
├── roundrobin >=0.0.2
├── typing-extensions >=3.7.4.3
└── werkzeug >=2.0.0
└── markupsafe >=2.1.1
Answers:
Not entirely sure why, but I had some other issues in the same environment (pip updates failing for example) and decided to delete the entire virtual env and create it from scratch using the lock file. Afterwards, the exact same code works perfectly fine.
I’m trying to run a very basic locust load testing which did work previously.
from locust import HttpUser, between, task
class QuickstartUser(HttpUser):
wait_time = between(1, 5)
@task
def get_status(self):
self.client.get("/status/")
Running the following command: locust -f <package-name>/tests/load_tests.py -r 20 -u 400 -H http://localhost:8000
yields the following error message when trying to access the web interface:
[2022-12-28 23:23:30,962] MacBook-Pro.fritz.box/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2022-12-28 23:23:30,968] MacBook-Pro.fritz.box/INFO/locust.main: Starting Locust 2.14.0
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/baseserver.py", line 34, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 1577, in handle
handler.handle()
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 464, in handle
result = self.handle_one_request()
File "/Users/<user>/Coding/PycharmProjects/<project>-fastapi/.venv/lib/python3.10/site-packages/gevent/pywsgi.py", line 656, in handle_one_request
if self.rfile.CLOSED:
AttributeError: '_io.BufferedReader' object has no attribute 'CLOSED'
2022-12-28T22:23:35Z <Greenlet at 0x106fbc3a0: _handle_and_close_when_done(<bound method WSGIServer.handle of <WSGIServer at , <bound method StreamServer.do_close of <WSGIServer, (<gevent._socket3.socket [closed] at 0x106fcb460 o)> failed with AttributeError
The following versions are being used:
$ poetry show locust --tree
locust 2.14.0 Developer friendly load testing framework
├── configargparse >=1.0
├── flask >=2.0.0
│ ├── click >=8.0
│ │ └── colorama *
│ ├── itsdangerous >=2.0
│ ├── jinja2 >=3.0
│ │ └── markupsafe >=2.0
│ └── werkzeug >=2.2.2
│ └── markupsafe >=2.1.1 (circular dependency aborted here)
├── flask-basicauth >=0.2.0
│ └── flask *
│ ├── click >=8.0
│ │ └── colorama *
│ ├── itsdangerous >=2.0
│ ├── jinja2 >=3.0
│ │ └── markupsafe >=2.0
│ └── werkzeug >=2.2.2
│ └── markupsafe >=2.1.1 (circular dependency aborted here)
├── flask-cors >=3.0.10
│ ├── flask >=0.9
│ │ ├── click >=8.0
│ │ │ └── colorama *
│ │ ├── itsdangerous >=2.0
│ │ ├── jinja2 >=3.0
│ │ │ └── markupsafe >=2.0
│ │ └── werkzeug >=2.2.2
│ │ └── markupsafe >=2.1.1 (circular dependency aborted here)
│ └── six *
├── gevent >=20.12.1
│ ├── cffi >=1.12.2
│ │ └── pycparser *
│ ├── greenlet >=2.0.0
│ ├── setuptools *
│ ├── zope-event *
│ │ └── setuptools * (circular dependency aborted here)
│ └── zope-interface *
│ └── setuptools * (circular dependency aborted here)
├── geventhttpclient >=2.0.2
│ ├── brotli *
│ ├── certifi *
│ ├── gevent >=0.13
│ │ ├── cffi >=1.12.2
│ │ │ └── pycparser *
│ │ ├── greenlet >=2.0.0
│ │ ├── setuptools *
│ │ ├── zope-event *
│ │ │ └── setuptools * (circular dependency aborted here)
│ │ └── zope-interface *
│ │ └── setuptools * (circular dependency aborted here)
│ └── six *
├── msgpack >=0.6.2
├── psutil >=5.6.7
├── pywin32 *
├── pyzmq >=22.2.1,<23.0.0 || >23.0.0
│ ├── cffi *
│ │ └── pycparser *
│ └── py *
├── requests >=2.23.0
│ ├── certifi >=2017.4.17
│ ├── charset-normalizer >=2,<3
│ ├── idna >=2.5,<4
│ └── urllib3 >=1.21.1,<1.27
├── roundrobin >=0.0.2
├── typing-extensions >=3.7.4.3
└── werkzeug >=2.0.0
└── markupsafe >=2.1.1
Not entirely sure why, but I had some other issues in the same environment (pip updates failing for example) and decided to delete the entire virtual env and create it from scratch using the lock file. Afterwards, the exact same code works perfectly fine.