【问题标题】:Module object is not callable in locust 0.13.0模块对象在 locust 0.13.0 中不可调用
【发布时间】:2020-06-18 07:58:12
【问题描述】:

当我运行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 但仍然是同样的错误。

【问题讨论】:

    标签: python python-3.x ubuntu locust load-generator


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,是的,是gevent版本问题。
    【解决方案2】:

    似乎您为 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-17
      • 2012-09-28
      • 2014-09-21
      • 2022-01-09
      • 2021-12-26
      • 2011-05-30
      相关资源
      最近更新 更多