asu-trans-ai-lab / grid2demand

A tool for generating zone-to-zone travel demand based on grid zones and gravity model
Apache License 2.0
71 stars 21 forks source link

PermissionError while saving CSV files in save_results_to_csv function, with simple try-except block #29

Open asu-trans-ai-lab opened 2 weeks ago

asu-trans-ai-lab commented 2 weeks ago

When running the save_results_to_csv function in the grid2demand package, a PermissionError is raised when attempting to save CSV files (e.g., zone.csv, node.csv, etc.). This may occur if the file is being accessed or locked by another process, or if the user does not have the necessary permissions for the target directory.

This issue prevents the program from completing its execution and disrupts the user experience, especially when the file is already open or locked.

Steps to Reproduce: Call the save_results_to_csv function in the package. Ensure that one of the output files (e.g., zone.csv) is either open or restricted in access. Run the function and observe the PermissionError. Expected Behavior: The program should gracefully handle the error, display a meaningful message to the user, and allow the program to continue or retry saving, rather than stopping entirely.

Suggested Solution: Implement error handling for file I/O operations in the save_results_to_csv function. A simple try-except block can catch the error and provide more information to the user about the issue. Additionally, we can suggest potential fixes (e.g., closing the file or checking file permissions) or even offer a retry mechanism.

try: self.save_zone(overwrite_file=overwrite_file) except PermissionError as e: print(f"Error: {e}. Please close any open files (e.g., zone.csv) and check your file permissions.")

Optionally retry or exit gracefully