2

当我运行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.7locust 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)

我运行 locust 0.13.0 文档示例,它也给了我同样的错误。我认为可能是它的 python 版本问题,所以我安装了 python 2.7 并再次在其上运行 locust 但仍然是同样的错误。

4

2 回答 2

2

Locust 0.13.0 相当老了。您可能想尝试最新版本 1.0.3。

但是假设你确实想要 Locust 0.13.0,你得到的错误是因为gevent已经破坏了它的 API,因为开发 locust 的版本gevent.signal不再是一种方法,而是一个模块。

(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'>

降级 gevent1.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%
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
于 2020-06-18T09:54:00.517 回答
0

似乎您为 python2 和 python3 都安装了 locust?我不确定实际的错误是什么,但假设您不想运行 python2,我建议您尝试:

为 python2 删除它

pip uninstall locustio

为python3安装它

pip3 install locust

(locust 包已从 locustio 重命名为 locust)

locust 1.0 版本中也有一些重大更改,因此您需要从 HttpLocust 更改为 HttpUser(请参阅https://docs.locust.io/en/stable/changelog.html#changelog-1- 0了解更多详情)

于 2020-06-18T09:55:19.657 回答