tags: 10. Mistakes 【 】Locust
1. Error message:
(1) The file is occupied
[2019-12-18 14:18:25,165] admin-PC/ERROR/stderr: Traceback (most recent call last):
File "d:\programs\python\python3.8\lib\site-packages\locust\core.py", line 394, in run
self.execute_next_task()
File "d:\programs\python\python3.8\lib\site-packages\locust\core.py", line 424, in execute_next_task
self.execute_task(task["callable"], *task["args"], **task["kwargs"])
File "d:\programs\python\python3.8\lib\site-packages\locust\core.py", line 436, in execute_task
task(self, *args, **kwargs)
File "G:\PycharmProjects\Locust_iwebshop_per\WorkFlow_Script\login_to_search.py", line 36, in search
os.remove(file_res)
PermissionError: [WinError 32] Another program is using this file and the process cannot access it.: 'SearchOutputdata.csv'
(2) Original code
def search(self):
file = open("Searchdata.csv","r")
table = csv.reader(file)
file_res = "search_output.csv"
file_in = os.path.exists(file_res)
if file_in:
os.remove(file_res)
file2 = open("search_output.csv","a")
for row in table:
keyword = row
print(keyword)
url = "/index.php?........&word="+str(keyword)
response = self.client.get(url).text
res = response.find(str(keyword))
time1 = datetime.datetime.now() # Get the current system time
if res>=0:
res = str(keyword)+"Query succeeded, test passed"+str(time1)
file2.write(res+"\n")
else:
res = str(keyword)+"Query failed, test failed" + str(time1)
file2.write(res + "\n")
file2.close()
Second, the reason
Because of errors caused by concurrency, the same file cannot be written and opened at the same time, and can be read at the same time.
There is such logic in the code, you need to first determine whether the test report file exists, if it exists, delete it, if it does not exist, create a file to write a test report.
But because the performance test requires multiple users to operate, if one user is writing, and another user just needs to determine whether the file exists, this problem will occur afterwards.
and so:
You can use the judgment of the existence of this file in non-performance tests such as automated functions and interfaces, but in performance tests, users have concurrent operations, so it is not suitable for this logic
Third, solve
(1) This problem can be solved by combining the technology of web automation writing into the database and writing the test report information into the database table.
(2) If you really need to judge and write a test report, you can put this code to determine whether the file exists in the WebsiteUser class, and it must be placed before task_set
Problem Description: Python3.7, using the library image inside PIL just wants to get the length and wide of the picture Newspaper is wrong D:\Python37-32\python.exe D:/pyFile/python_script/img_read.py...
When making image processing, I used three modules OS, PIL, CV2. I encountered a bug who plagued one morning, I investigated several resource monitor ~~~, bug as follows: Description of Requirement: 1...
Problem Description Kafka deployed in the Windows environment is hung after running for a period of time. View loglogs/server.log Discover the following errors: reason When the consumer's offset log i...
Paste the error message first Cause Analysis: Failed to clean up the consumer_offset record in the D:\tmp\kafka-logs directory consumer_offset is the topic that Kafka automatically saves the offset, a...
The scenario is as follows:I have a project A in Disk D, There is a class library AbsDataCache, which has 3 cs files, among which CacheManager is used to encapsulate the cache cache of asp.net and the...
kuaiya\kzippb-This file is being used by another program and the process cannot access it. Problem Description: Usually when deleting a folder or deleting a single file, we often encounter the followi...
Problem: The ASP.NET Core project deployed on IIS will cause a process occupation error when updating Initial solution: 1. Close the application pool 2. Close the website 3. Update the p...
Article catalog First, error information Second, the solution First, error information FLUTTER Mixed Development Project: In the Android project, embed the flutter page, accidentally run the Flutter p...
Report an error: Another program has locked a part of the file and the process cannot access it Cannot open the disk "E:\Ubuntu\Ubuntu 64-bit .vmdk" or one of the snapshot disks it depends o...
VMware Workstation fails to start the virtual machine. It prompts: Another program has locked a part of the file, and the process cannot be accessed. The screenshot is as follows: wrong reason: When t...