我运行locust -f /desktop/locustfile.py
时发生以下错误
[2020-06-18 12:09:27,858] fatima/INFO/locust.main: Starting web monitor at *:8089
[2020-06-18 12:09:27,858] fatima/ERROR/stderr: Traceback (most recent call last):
[2020-06-18 12:09:27,858] fatima/ERROR/stderr: File "/home/fatima/.local/bin/locust", line 11, in <module>
[2020-06-18 12:09:27,858] fatima/ERROR/stderr:
[2020-06-18 12:09:27,858] fatima/ERROR/stderr: sys.exit(main())
[2020-06-18 12:09:27,858] fatima/ERROR/stderr: File "/home/fatima/.local/lib/python2.7/site-packages/locust/main.py", line 525, in main
[2020-06-18 12:09:27,858] fatima/ERROR/stderr:
[2020-06-18 12:09:27,858] fatima/ERROR/stderr: gevent.signal(signal.SIGTERM, sig_term_handler)
[2020-06-18 12:09:27,859] fatima/ERROR/stderr: TypeError
[2020-06-18 12:09:27,859] fatima/ERROR/stderr: :
[2020-06-18 12:09:27,859] fatima/ERROR/stderr: 'module' object is not callable
[2020-06-18 12:09:27,859] fatima/ERROR/stderr:
我正在使用 python:3.7 , 蝗虫0.13.0 这是代码
import random
from locust import HttpLocust, TaskSet, between
products = [
'0PUK6V6EV0',
'1YMWWN1N4O',
'2ZYFJ3GM2N',
'66VCHSJNUP',
'6E92ZMYYFZ',
'9SIQT8TOJO',
'L9ECAV7KIM',
'LS4PSXUNUM',
'OLJCESPC7Z']
def index(l):
l.client.get("/")
def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)})
def browseProduct(l):
l.client.get("/product/" + random.choice(products))
class UserBehavior(TaskSet):
def on_start(self):
index(self)
tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
}
class WebsiteUser(HttpLocust):
task_set = UserBehavior
wait_time = between(1, 10)
我运行了蝗虫0.13.0文档example,它也给我同样的错误。我以为可能是它的python版本问题,所以我安装了python 2.7并再次在其上运行蝗虫,但仍然是相同的错误。
答案 0 :(得分:1)
蝗虫0.13.0相当老。您可能要尝试使用最新版本1.0.3。
但是假设您确实想要Locust 0.13.0,那么您得到的错误是因为{locus的版本不再针对gevent
,因为gevent.signal
已经破坏了它的API一个方法,但一个模块。
(locust2) hyperair@blah:/tmp% pip freeze | grep gevent
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
gevent==20.6.2
geventhttpclient-wheels==1.3.1.dev2
(locust2) hyperair@blah:/tmp% python
Python 2.7.18rc1 (default, Apr 7 2020, 12:05:55)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
>>> gevent.signal
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'signal'
>>> from gevent import signal
>>> signal
<module 'gevent.signal' from '/home/hyperair/.virtualenvs/locust2/lib/python2.7/site-packages/gevent/signal.pyc'>
将gevent降级为1.2.2
使其起作用:
(locust) hyperair@blah:/tmp% pip install gevent==1.2.2
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting gevent==1.2.2
Using cached gevent-1.2.2-cp27-cp27mu-manylinux1_x86_64.whl (1.6 MB)
Requirement already satisfied: greenlet>=0.4.10 in /home/hyperair/.virtualenvs/locust/lib/python2.7/site-packages (from gevent==1.2.2) (0.4.16)
Installing collected packages: gevent
Attempting uninstall: gevent
Found existing installation: gevent 20.6.2
Uninstalling gevent-20.6.2:
Successfully uninstalled gevent-20.6.2
Successfully installed gevent-1.2.2
(locust) hyperair@blah:/tmp% cd ./locust
(locust) hyperair@blah:/tmp/locust% ls
locustfile.py locustfile.pyc
(locust) hyperair@blah:/tmp/locust% locust -f locustfile.py
[2020-06-18 17:51:08,898] blah/INFO/locust.main: Starting web monitor at *:8089
[2020-06-18 17:51:08,898] blah/INFO/locust.main: Starting Locust 0.13.0
^C[2020-06-18 17:51:10,144] blah/ERROR/stderr: KeyboardInterrupt
[2020-06-18 17:51:10,144] blah/ERROR/stderr: Thu Jun 18 17:51:10 2020
[2020-06-18 17:51:10,144] blah/ERROR/stderr:
[2020-06-18 17:51:10,145] blah/INFO/locust.main: Shutting down (exit code 0), bye.
[2020-06-18 17:51:10,145] blah/INFO/locust.main: Cleaning up runner...
[2020-06-18 17:51:10,145] blah/INFO/locust.main: Running teardowns...
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 0 0(0.00%) 0.00 0.00
Percentage of the requests completed within given times
Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 100%
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
答案 1 :(得分:0)
似乎您为python2和python3安装了蝗虫?我不确定实际的错误是什么,但是假设您不希望运行python2,我建议您尝试:
为python2删除它
pip uninstall locustio
为python3安装
pip3 install locust
(蝗虫包装已从locustio重命名为locust)
蝗虫1.0发行版中也有一些重大更改,因此您需要从HttpLocust更改为HttpUser(有关更多详细信息,请参见https://docs.locust.io/en/stable/changelog.html#changelog-1-0)