OpenSeizureDetector / OpenSeizureDatabase

This repository contains the toolkit to create and proocess the database of seizure and seizure-like data that has been contributed by OpenSeizureDetector users to contribute to research to improve seizure detection algorithms (Open Seizure Toolkit, OSTK).
https://openseizuredetector.org.uk
Other
4 stars 3 forks source link

Files open are not closed properly if an exception is raised in Summarize Data #7

Closed pmithrandir closed 8 months ago

pmithrandir commented 8 months ago

In the code we have many of the file openning that are done in this model : ` outfile = open(outFilePath, 'w')

dataTime = dateutil.parser.parse(analyser.eventObj['dataTime'])

pageData={
    'events': {
        'tcSeizures': tcSeizuresLst,
        'allSeizures': allSeizuresLst,
        'falseAlarms': [],
        'otherEvents': []
    }
}
#print(pageData)
print("Rendering index page")
outfile.write(template.render(data=pageData))
outfile.close()`

The problem is that if something is going bad between open and close, the file will never be closed properly.

Using either try except finally of with open(fname) as infile: to resolve that issue.