gpt4 book ai didi

python - 模块对象在 locust 0.13.0 中不可调用

转载 作者:行者123 更新时间:2023-12-04 18:29:41 25 4
gpt4 key购买 nike

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

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

最佳答案

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

但是假设你确实想要 Locust 0.13.0,你得到的错误是因为 gevent自从开发 locust 的版本之后,它的 API 就被破坏了 -- 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'>

将 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%
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------

关于python - 模块对象在 locust 0.13.0 中不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62445130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com