From 0e0a3db307fa022aa8d6a88a3618252a0ed048c0 Mon Sep 17 00:00:00 2001 From: Jakub Kliszko Date: Sun, 16 Apr 2023 00:09:18 +0200 Subject: [PATCH] fix: fix for Windows --- lab3/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lab3/main.py b/lab3/main.py index 51e74966..c4a18151 100644 --- a/lab3/main.py +++ b/lab3/main.py @@ -4,9 +4,10 @@ Program that optimizes Rastrigin function: file_ (x_point_value, y_point_value) Using Evolutionary Strategy (μ, λ). """ import sys +import os import time import tempfile -from cv2 import cv2 +import cv2 import matplotlib.pyplot as plt import numpy as np @@ -109,7 +110,7 @@ def output(population_output): # define the visualization params colors = np.random.rand(output_length) - with tempfile.NamedTemporaryFile(suffix=".png") as file_: + with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as file_: # iterate over the optimization steps # generate random 2D data - replace it with the results from your # algorithm @@ -142,6 +143,12 @@ def output(population_output): cv2.destroyAllWindows() + try: + file_.close() + os.unlink(file_.name) + except: + pass + def user_input(): """ Handle user terminal arguments"""