"IndexError: Cannot choose from an empty sequence" between tasks
See original GitHub issueDescription of issue
Spurious error messages during execution.
Environment settings
- OS: Official ubuntu:18.04 Docker container
- Python version: 3.6.7
- Locust version: 0.9.0
Steps to reproduce
I’ve registered all my tasks by looping through the OpenAPI JSON for the API like this:
class APIRequest(TaskSet):
def setup(self) -> None:
for api_path, properties in self.client.get('/api/doc/?format=openapi').json()['paths'].items():
[exclude some API paths]
self.schedule_task(self.api_task, args=[api_path])
def api_task(self, path: str) -> None:
response = self.client.get("/api{}?limit=1000".format(path))
assert response.status_code == HTTPStatus.OK, response.content.decode()
class ApiRequests(HttpLocust):
task_set = APIRequest
min_wait = 200
max_wait = 1000
host = 'https://{}'.format(os.environ['WEB_HOSTNAME'])
if __name__ == '__main__':
locust = ApiRequests()
locust.run()
I then run Locust: locust --csv=output/ --locustfile=api.py --no-web --run-time=5m
Expected behavior
Locust should run for five minutes and return successfully, reporting progress as it runs.
Actual behavior
Even if the run is successful, Locust will frequently print one, two or three error messages such as the below between each time it prints the summary table:
[2019-02-04 00:19:23,150] 2e0a2ecc40ea/ERROR/stderr: Traceback (most recent call last):
File "/src/app/.venv/lib/python3.6/site-packages/locust/core.py", line 358, in run
self.schedule_task(self.get_next_task())
File "/src/app/.venv/lib/python3.6/site-packages/locust/core.py", line 419, in get_next_task
return random.choice(self.tasks)
File "/src/app/.venv/lib/python3.6/random.py", line 260, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
IndexError: Cannot choose from an empty sequence
I am trying to run this command python run.py --mode MLE and got this error. I am not able to find the correct...
Read more >Python error IndexError Cannot choose from an empty sequence
Your file name seems to be random. Random is a module and can not be used as a file name. Change the filename...
Read more >Probability Calculator - IndexError: Cannot choose from an ...
That means that you move all 19 to the contents, draw them, and then try to draw the twentieth which fails because the...
Read more >IndexError: Cannot choose from an empty sequence
I am getting the following error while loading data into the dataloader. why the data loader is unable to load all images and...
Read more >Python Choice Function - Scaler Topics
When we pass any empty sequence to the choice() function, it will throw an IndexError. An empty sequence means it could be an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Setup is run only once (and thus should never have been made an object method, that is a design mistake), so only the first TaskSet instance will have self.apis value.
If you set a class variable (LoadTestBehaviour.apis instead of self.apis), it should work.
Oh I see what you are trying to do now. remove the call to schedule_tasks. I dont think you are meant to call it yourself. Instead, just populate a list of paths in setup and pick from that list inside your task method.