The locust is high and a csv test report occurs, reporting an error PermissionError: [WinError 32] Another program is using this file and the process cannot access it. :'SearchOutputdata.csv'

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

Intelligent Recommendation

python3.7: PermissionError: [WinError 32] The process cannot access the file because it is......

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...

[Winerror 32] Another program is using this file, the process cannot be accessed, # image processing

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...

Kafka in Windows Error: java.nio.file.filesystemXception: Another program is using this file, the process cannot access the process, the process cannot be accessed

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...

An error was reported when starting kafka: java.nio.file.FileSystemException, another program is using this file, and the process cannot access it.

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...

More Recommendation

Solve when deleting a folder or file: another program is using this file and the process cannot access it.

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...

Solve the problem of deploying ASP.NET Core to IIS, updating the project "another program is using this file, the process cannot access"

  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...

[Error Record] Flutter mixed development error (java.nio.file.filesystemException: xxx / r.jar: Another program is using this file, the process cannot be accessed.)

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...

VMware reports an error: "Another program has locked a part of the file and the process cannot access it"

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 turned on the virtual machine error: another program has locked a part of the file, the process cannot access

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...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top