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.

Question: debugging in pycharm (or other arbitrary IDE)

See original GitHub issue

Hello, so quick question. I have locust installed in a venv on python 3 (locustio==0.8a2). I’ve been building and testing a locust python script, but I’m trying to traverse some complicated json responses. In order to run a locust script, you have to run locust loadtest-file.py

Is it possible to attach a debugger while running a locust script?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

26reactions
MattF-NSIDCcommented, Oct 20, 2017

Took me a minute to get there (specifically to realize I had to call .run()) so I figured I’d share:

I create a subclass of HttpLocust called WebsiteUser. To execute a single instance from the CLI, I added:

if __name__ == '__main__':
    x = WebsiteUser()
    x.run()

Then run python locustfily.py. If I have a pdb breakpoint in one of my tasks, this triggers the breakpoint. Full example locustfile.py:

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):
    @task
    def index(self):
        import pdb; pdb.set_trace()
        self.client.get("/")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior 
    host = 'http://google.com'
    min_wait = 1000
    max_wait = 2000

if __name__ == '__main__':
    WebsiteUser().run()
16reactions
GabLeRouxcommented, Jul 10, 2018

Here I managed to get Intellij Idea (Similar to PyCharm) to break while locust is running.

image

I used python remote debug run configuration, followed instructions. In my case, I just used a virtualenv and installed locustio and pydevd directly. 🎉

It should break automatically right under the following line (I think break point is optional):

pydevd.settrace('localhost', port=12345, stdoutToServer=True, stderrToServer=True)

👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Step 2. Debug your first Python application - PyCharm
Debugging in detail​​ The Debug tool window shows dedicated panes for frames, variables, and watches, and the console, where all the input and...
Read more >
Run/debug configurations | PyCharm Documentation - JetBrains
Learn how to use run configurations to run/debug your code in PyCharm with various startup properties.
Read more >
Debug | PyCharm Documentation - JetBrains
How to configure the debugger settings. Learn more about launching, pausing and stopping a debugging session, and stepping through the program.
Read more >
Get started | PyCharm Documentation - JetBrains
To start debugging your application, press Shift+F9 . Then go through the program execution step by step (see the available options in the...
Read more >
Debugging During Testing - PyCharm Guide - JetBrains
When writing tests, use the PyCharm "visual debugger" to interactively poke around in the context of a problem.
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