Błąd #8247

Strumień pliku jest zamykany dopiero przy destrukcji obiektu

Added by Kamil Tagowski over 5 years ago.

Status:NowyStart date:27 Oct 2017
Priority:NormalnyDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

Plik w corpus2 jest zapisywany dopiero przy destrukcji obiektu, funkcja finish() nie kończy zapisu.

Przykładowy kod, który nie zamyka strumienia pliku w języku Python

reader = corpus2mwe.CclMWEReader(path, self.tagset)
reader.set_files(path)
reader.use_annotations(True)
doc = reader.read()
gz_writer = corpus2.TokenWriter.create_path_writer('ccl:gz', opath , corpus2.get_named_tagset('nkjp'))
for chunk in doc.paragraphs():
    gz_writer.write_chunk(chunk)

gz_writer.finish()
readerGZ  = corpus2.TokenReader.create_path_reader('ccl:gz', self.tagset, opath + '.gz')
print readerGZ.get_next_token().orth_utf8()       

Wywołanie destruktora powoduje już naturalne zachowanie i zamknięcie strumienia.

for chunk in doc.paragraphs():
    gz_writer.write_chunk(chunk)

del gz_writer

readerGZ = corpus2.TokenReader.create_path_reader('ccl:gz', self.tagset, opath + '.gz')
print readerGZ.get_next_token().orth_utf8()

Możliwe rozwiązanie

Zmiana metody gz_writer.finish() na metode czysto wirtualną i implementacja mechanizmu zamykającego strumień w wybranym writerze np. ccl:gz

Also available in: Atom PDF