diff --git a/beets/importer.py b/beets/importer.py index 28f4308a4..f8d4794c4 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -57,6 +57,7 @@ def tag_log(logfile, status, path): """ if logfile: print >>logfile, '%s %s' % (status, path) + logfile.flush() def log_choice(config, task): """Logs the task's current choice if it should be logged. diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 41ce671ca..41928a99f 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -593,35 +593,37 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded, if resume is None and quiet: resume = False - # Perform the import. - importer.run_import( - lib = lib, - paths = paths, - resume = resume, - logfile = logfile, - color = color, - quiet = quiet, - quiet_fallback = quiet_fallback, - copy = copy, - write = write, - art = art, - delete = delete, - threaded = threaded, - autot = autot, - choose_match_func = choose_match, - should_resume_func = should_resume, - singletons = singletons, - timid = timid, - choose_item_func = choose_item, - query = query, - incremental = incremental, - ignore = ignore, - ) + try: + # Perform the import. + importer.run_import( + lib = lib, + paths = paths, + resume = resume, + logfile = logfile, + color = color, + quiet = quiet, + quiet_fallback = quiet_fallback, + copy = copy, + write = write, + art = art, + delete = delete, + threaded = threaded, + autot = autot, + choose_match_func = choose_match, + should_resume_func = should_resume, + singletons = singletons, + timid = timid, + choose_item_func = choose_item, + query = query, + incremental = incremental, + ignore = ignore, + ) - # If we were logging, close the file. - if logfile: - print >>logfile, '' - logfile.close() + finally: + # If we were logging, close the file. + if logfile: + print >>logfile, '' + logfile.close() # Emit event. plugins.send('import', lib=lib, paths=paths) diff --git a/docs/changelog.rst b/docs/changelog.rst index 72e23e7a3..8479320db 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,6 +33,8 @@ Changelog layer. See :ref:`writing-plugins`. * A reasonable error message is now shown when the import log file cannot be opened. +* The import log file is now flushed and closed properly so that it can be used + to monitor import progress, even when the import crashes. * Fix a bug in the ``rewrite`` plugin that broke the use of multiple rules for a single field. * Fix a crash with non-ASCII characters in bytestring metadata fields (e.g.,