question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hangs on locust import.

See original GitHub issue

When Trying to import the locust library ipython hangs. When using the default interpreter the import works correctly. Locust website

Python 3.7.3 (default, Mar 27 2019, 09:23:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

[ins] In [1]: import locust
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/local/lib/python3.7/site-packages/locust/core.py in <module>
     18
---> 19 from . import events
     20 from .clients import HttpSession

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _lock_unlock_module(name)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in acquire(self)

KeyboardInterrupt:

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/local/lib/python3.7/site-packages/locust/__init__.py in <module>
----> 1 from .core import HttpLocust, Locust, TaskSet, TaskSequence, task, seq_task
      2 from .exception import InterruptTaskSet, ResponseError, RescheduleTaskImmediately
      3

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in __exit__(self, *args, **kwargs)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in release(self)

RuntimeError: cannot release un-acquired lock

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-1-5686ac03cced> in <module>
----> 1 import locust

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in __exit__(self, *args, **kwargs)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in release(self)

RuntimeError: cannot release un-acquired lock

Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 10, in <module>
    sys.exit(start_ipython())
  File "/usr/local/lib/python3.7/site-packages/IPython/__init__.py", line 125, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python3.7/site-packages/IPython/terminal/ipapp.py", line 356, in start
    self.shell.mainloop()
  File "/usr/local/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 498, in mainloop
    self.interact()
  File "/usr/local/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 481, in interact
    code = self.prompt_for_code()
  File "/usr/local/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 410, in prompt_for_code
    **self._extra_prompt_options())
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 738, in prompt
    return run_sync()
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 727, in run_sync
    return self.app.run(inputhook=self.inputhook, pre_run=pre_run2)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 709, in run
    return run()
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 683, in run
    return f.result()
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/future.py", line 149, in result
    raise self._exception
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
    new_f = coroutine.throw(exc)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 658, in _run_async2
    result = yield f
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 86, in step_next
    new_f = coroutine.send(None)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 598, in _run_async
    with self.input.attach(read_from_input):
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/input/vt100.py", line 147, in _attached_input
    loop.add_reader(fd, callback)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/posix.py", line 272, in add_reader
    self.selector.register(fd)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/select.py", line 76, in register
    sel.register(fd)
  File "/usr/local/lib/python3.7/site-packages/prompt_toolkit/eventloop/select.py", line 131, in register
    self._sel.register(fd, selectors.EVENT_READ, None)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 520, in register
    kev = select.kevent(key.fd, select.KQ_FILTER_READ,
AttributeError: module 'select' has no attribute 'kevent'

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

4reactions
mardukbpcommented, Aug 10, 2020

This issue arises due to gevent’s monkey-patching of code related to threads (see #2785). TL;DR use the following launcher script for IPython:

#!/usr/bin/env python
import gevent.monkey
gevent.monkey.patch_all()

import IPython
IPython.start_ipython()

Now importing locust should work.

0reactions
rtacconicommented, Sep 2, 2020

I am wondering how I can configure that in Atom

Read more comments on GitHub >

github_iconTop Results From Across the Web

python google spanner hangs when used with locust
I am currently using Google Cloud Shell and installed locust by entering pip3 install locust . Error is Unable to import 'locust' ....
Read more >
Writing a locustfile — Locust 2.14.0 documentation
A locust file is just a normal Python module, it can import code from other files or packages. class QuickstartUser(HttpUser):. Here we define...
Read more >
Quick Tutorial on Locust
A locust file is just a normal Python module, it can import code from other files or packages. class MyUser(HttpUser):. Here we define...
Read more >
Locust - Read the Docs
from locust import HttpLocust, TaskSet, task, between class UserBehavior(TaskSet): def on_start(self):. """ on_start is called when a Locust ...
Read more >
locust - PyPI
Locust is an easy to use, scriptable and scalable performance testing tool. ... from locust import HttpUser, task, between class QuickstartUser(HttpUser): ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found