Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def Main():
Target means run this function when a thread is initiated."""
myThread = threading.Thread(target=MyFunction)
myThread.start() # Starting a thread
fp = open("def.txt")
fp.close()
try:
fp = open("def.txt")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

Problem
This line of code might contain a resource leak. Resource leaks can cause your system to slow down or crash.

Fix
Consider closing the following resource: fp. The resource is allocated by call builtins.open. Execution paths that do not contain closure statements were detected. To prevent this resource leak, close fp in a try-finally block or declare it using a with statement.

More info
View details about the with statement in the Python developer's guide (external link).

#fp.close()


if __name__ == '__main__':
Expand Down