I am beginner to python and I have a question which is I run the python program which is a program for saving a log file from gz format into csv format, but unfortunately when I try to terminate the program, I terminate the program forcefully, which makes the file not to be written in my computer, so how to terminate manually without deleting a file. Below is my code:
# List of all gz files
gz_files = (gz for gz in glob.glob(os.path.join(GZ_DIR, '*.gz')))
# Loop through all gz files
for gz_file in gz_files:
    sql_file = gz_file[:-3]
    sql_file = sql_file[:-4] + '.csv'
    with open(sql_file, 'wb') as out_file:
        with gzip.open(gz_file, 'rb') as in_file:
            while True:
                chunk = in_file.read(1024)
                if not chunk:
                    break
                out_file.write(chunk)
    # Step 2: import to sql
    import_sql(out_file, DB_HOST, DB_USER, DB_PASS, DB_NAME)
    # Step 3: remove uncompresed file
    # os.remove(sql_file)
    # Step 4: in loop, back to step 1 automatically for another gz files
