I'm very new to Locust and I'm having some problems. I have a python script that logs a user into our webpage and navigates to a certain point. We want to test the load of 1000s of users logging in the exact same way. I'm having trouble finding what I need in the Locust documentation, though.
Does anyone know if it's even possible to run a script that isn't a get/put action using Locust? If yes, is there a way to know the iteration that Locust is in and pass that number to the script? Ex: if it's just spawned user 234, pass 234 to the script so it can go get an id.
Does that make sense? Sorry if it's an obvious answer, I'm kind of wading through this on my own with no prior experience and I'm not really technical.
Thanks!
Related
I am using a Python script to query our wireless controllers (ArubaOS). They offer an API function called "showcommand" which let's you send any (perhaps not any but anyway) of the normal commands that you would type in at the CLI (often these are like "show ... some stuff", hence showcommand).
It normally does a good job of returning some structured data. However I am running a particular command which has an issue. When you run the command on the CLI it initially displays a warning like "This command may take some time to run, please be patient" and then it displays the actual data. When I run the command from my Python script all I get back is the warning, no actual useful data.
I can't think of a way to solve this. Maybe if there was a way to introduce a delay immediately after the request is made to wait for the data? But I guess that would need to be something within the requests module, and I can't see a likely candidate. Does anyone have any ideas how to get around this?
Thanks,
Guy
Ok, so I'm a total noob with aspirations of learning to code. I've read about a guy who, for example, wrote a script which, if he was at work past a certain time, would automatically send a text to his wife stating he would be late. I want to do something sorta similar.
What I want in essence is a script that will log in to a website at a certain time of day, check if a box/text is green/yes or red/no, and send a text or notification to my phone informing me of the result each day.
The progress I've made so far is installing Python, installing PyCharm and done some research about tools I could use toward achieving my goal. Selenium seems like it would be capable of logging into the website, but I've no idea how to go about setting up a conditional statement to check the result, nor how I could set it up to send a text/notification to my phone. Also, if there is a more appropriate tool I should look into rather than Selenium and Python, I'm not attached to the idea of using these specific tools.
Finally, I realize that this may end up being too complicated for a first project, so I'd be up for hiring a freelancer to set this up. Equally, if this is something that could feasibly be written by someone with very little knowledge of coding such as myself, I'd really appreciate some direction from an expert!
Thanks for any input!
You are on the right track with selenium for web form automation. Sending notification however would require something else as was pointed out, and if you're on windows you can use windows task scheduler to automate, to performed only on certain time of day etc.
To make things more simplified, you can also look up general purpose automation programs that might support all these features together. For example, JRVSInputs uses selenium for web auto-fills https://jrvs.in/forums/viewtopic.php?t=182 and have features to send email or windows notifications. It can convert all its scripts into a neat batch file, you can then automate this batch file in the task scheduler.
Okay, so basically I am creating a website. The data I need to display on this website is delivered twice daily, where I need to read the delivered data from a file and store this new data in the database (instead of the old data).
I have created the python functions to do this. However, I would like to know, what would be the best way to run this script, while my flask application is running? This may be a very simple answer, but I have seen some answers saying to incorporate the script into the website design (however these answers didn't explain how), and others saying to run it separately. The script needs to run automatically throughout the day with no monitoring or input from me.
TIA
Generally it's a really bad idea to put a webserver to handle such tasks, that is the flask application in your case. There are many reasons for it so just to name a few:
Python's Achilles heel - GIL.
Sharing system resources of the application between users and other operations.
Crashes - it happens, it could be unlikely but it does. And if you are not careful, the web application goes down along with it.
So with that in mind I'd advise you to ditch this idea and use crontabs. Basically write a script that does whatever transformations or operations it needs to do and create a cron job at a desired time.
I would like to recreate some data in my project every 30 minutes (prices that change). also I got another job that needs to refresh every minute.
Now I heard I should use a daemon. but I'm not sure how that works.
Can someone put me into the right direction.
Also should i make an extra model to save that temporary data or is that part of the daemon?
PS: not sure if stack overflow can be used for this sort of questions, but i don't know where to search for this sort of information
You don't want a daemon. You just want cron jobs.
The best thing to do is to write your scripts as custom Django management commands and use cron to trigger them to run at the specified intervals.
Question for Python 2.6
I would like to create an simple web application which in specified time interval will run a script that modifies the data (in database). My problem is code for infinity loop or some other method to achieve this goal. The script should be run only once by the user. Next iterations should run automatically, even when the user leaves the application. If someone have idea for method detecting apps breaks it would be great to show it too. I think that threads can be the best way to achive that. Unfortunately, I just started my adventure with Python and don't know yet how to use them.
The application will have also views showing database and for control of loop script.
Any ideas?
You mentioned that you're using Google App Engine. You can schedule recurring tasks by placing a cron.yaml file in your application folder. The details are here.
Update: It sounds like you're not looking for GAE-specific solutions, so the more general advice I'd give is to use the native scheduling abilities of whatever platform you're using. Cron jobs on a *nix host, scheduled tasks on Windows, cron.yaml on GAE, etc.
In your other comments you've suggested wanting something in Python that doesn't leave your script executing, and I don't think there's any way to do this. Some process has to be responsible for kicking off whatever it is you need done, so either you do it in Python and keep a process executing (even if it's just sleeping), or you use the platform's scheduling tools. The OS is almost guaranteed to do a better job of this than your code.
i think you'd want to use cron. write your script, and have cron run it every X minutes / hours.
if you really want to do this in Python, you can do something like this:
while(True):
<your app logic here>
sleep(TIME_INTERVAL)
Can you use cron to schedule the job to run at certain intervals? It's usually considered better than infinite loops, and was designed to help solve this sort of problem.
There's a very primitive cron in the Python standard library: import sched. There's also threading.Timer.
But as others say, you probably should just use the real cron.