diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 54496dc32dd..cf6e3b7c3e8 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -357,15 +357,18 @@ def format_list(specs): max_width = max(len(f[0]) for f in formatted) path_fmt = "%%-%ds%%s" % (max_width + 2) - for string, spec in formatted: - if not string: - print() # print newline from above - continue + # getting lots of prefixes requires DB lookups. Ensure + # all spec.prefix calls are in one transaction. + with spack.store.db.read_transaction(): + for string, spec in formatted: + if not string: + print() # print newline from above + continue - if paths: - print(path_fmt % (string, spec.prefix)) - else: - print(string) + if paths: + print(path_fmt % (string, spec.prefix)) + else: + print(string) if groups: for specs in iter_groups(specs, indent, all_headers):