You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Python pyodbc library to execute queries within Locust tasks, the tasks seem to block or get stuck, preventing other tasks from executing concurrently. However, the same code works as expected when executed within a ThreadPool using concurrent.futures.
Steps to Reproduce
Run the Locust file (db_locust.py) with the command: locust -f db_locust.py --headless -u10 -r10 --host=localhost
Expected behavior: Multiple Locust users should be able to execute the queries concurrently without blocking.
Actual behavior: Only one Locust user can execute the query at a time, and other users get stuck or blocked until the previous user completes the query.
Code Examples
The issue description includes two code examples:
A Locust file (db_locust.py) that demonstrates the blocking behavior when using pyodbc within Locust tasks. This file also sets up the required database table and data.
A separate Python file that executes the same queries using a ThreadPool from concurrent.futures, and this code works as expected without any blocking issues. (Not provided in the issue but I can share this code that's working).
Environment
Python version: Latest
Locust version: Latest
pyodbc version: Latest
Database: SQL Server or PostgreSQL (Latest)
Operating System: Windows and Linux (issue is operating system agnostic)
Log Output
Actual
[...]: Loaded data to table SampleTable_1711171627
[...]: Ramping to 10 users at a rate of 10.00 per second
[...]: All users spawned: {"TestUser": 10} (10 total users)
[...]: User 1 started
[...]: User 1 connection established
[...]: User 1 Executing Query select * from SampleTable_1711171627
[...]: User 1 completed Query
[...]: User 2 started
[...]: User 2 connection established
[...]: User 2 Executing Query select * from SampleTable_1711171627
[...]: User 2 completed Query
Expected
[...] User 1 started
[...] User 2 started
[...] User 3 started
[...] User 1 connection established
[...] User 2 connection established
[...] User 3 connection established
[...] User 1 Executing Query select * from SampleTable_1711171627
[...] User 2 Executing Query select * from SampleTable_1711171627
[...] User 3 Executing Query select * from SampleTable_1711171627
[...] User 1 completed Query
[...] User 2 completed Query
[...] User 3 completed Query
Additional Information
The issue seems to be specific to the combination of Locust and pyodbc, as the code works as expected when executed within a ThreadPool. The blocking behavior occurs with both SQL Server and PostgreSQL databases, suggesting that the issue is not database-specific.
The blocking behavior occurs when executing queries with pyodbc within Locust tasks, but it does not occur when using time.sleep() instead of conn.execute().
Any assistance or insights into this issue would be greatly appreciated.
This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!
Prerequisites
Description
Issue Description
When using the Python
pyodbc
library to execute queries within Locust tasks, the tasks seem to block or get stuck, preventing other tasks from executing concurrently. However, the same code works as expected when executed within aThreadPool
usingconcurrent.futures
.Steps to Reproduce
db_locust.py
) with the command:locust -f db_locust.py --headless -u10 -r10 --host=localhost
Expected behavior: Multiple Locust users should be able to execute the queries concurrently without blocking.
Actual behavior: Only one Locust user can execute the query at a time, and other users get stuck or blocked until the previous user completes the query.
Code Examples
The issue description includes two code examples:
db_locust.py
) that demonstrates the blocking behavior when usingpyodbc
within Locust tasks. This file also sets up the required database table and data.ThreadPool
fromconcurrent.futures
, and this code works as expected without any blocking issues. (Not provided in the issue but I can share this code that's working).Environment
Log Output
Actual
Expected
Additional Information
The issue seems to be specific to the combination of Locust and
pyodbc
, as the code works as expected when executed within aThreadPool
. The blocking behavior occurs with both SQL Server and PostgreSQL databases, suggesting that the issue is not database-specific.The blocking behavior occurs when executing queries with
pyodbc
within Locust tasks, but it does not occur when usingtime.sleep()
instead ofconn.execute()
.Any assistance or insights into this issue would be greatly appreciated.
Command line
locust -f db_locust.py --headless -u10 -r10 --host=localhost
Locustfile contents
Python version
3.12.2
Locust version
2.24.1
Operating system
Windows
The text was updated successfully, but these errors were encountered: