Use a single process in testing, not the Pool
This commit is contained in:
parent
9af8d4f186
commit
10f22834ee
@ -75,13 +75,21 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
logging.getLogger().handlers[0].level = logging.ERROR
|
logging.getLogger().handlers[0].level = logging.ERROR
|
||||||
with multiprocessing.Pool(self.process_count) as pool:
|
|
||||||
list(
|
if self.process_count == 1:
|
||||||
tqdm.tqdm(
|
for doc_id in document_ids:
|
||||||
pool.imap_unordered(update_document_archive_file, document_ids),
|
update_document_archive_file(doc_id)
|
||||||
total=len(document_ids),
|
else: # pragma: no cover
|
||||||
disable=self.no_progress_bar,
|
with multiprocessing.Pool(self.process_count) as pool:
|
||||||
),
|
list(
|
||||||
)
|
tqdm.tqdm(
|
||||||
|
pool.imap_unordered(
|
||||||
|
update_document_archive_file,
|
||||||
|
document_ids,
|
||||||
|
),
|
||||||
|
total=len(document_ids),
|
||||||
|
disable=self.no_progress_bar,
|
||||||
|
),
|
||||||
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.stdout.write(self.style.NOTICE("Aborting..."))
|
self.stdout.write(self.style.NOTICE("Aborting..."))
|
||||||
|
@ -93,12 +93,12 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
|||||||
work_pkgs.append(_WorkPackage(first_doc, second_doc))
|
work_pkgs.append(_WorkPackage(first_doc, second_doc))
|
||||||
|
|
||||||
# Don't spin up a pool of 1 process
|
# Don't spin up a pool of 1 process
|
||||||
if options["processes"] == 1:
|
if self.process_count == 1:
|
||||||
results = []
|
results = []
|
||||||
for work in tqdm.tqdm(work_pkgs, disable=self.no_progress_bar):
|
for work in tqdm.tqdm(work_pkgs, disable=self.no_progress_bar):
|
||||||
results.append(_process_and_match(work))
|
results.append(_process_and_match(work))
|
||||||
else:
|
else: # pragma: no cover
|
||||||
with multiprocessing.Pool(processes=options["processes"]) as pool:
|
with multiprocessing.Pool(processes=self.process_count) as pool:
|
||||||
results = list(
|
results = list(
|
||||||
tqdm.tqdm(
|
tqdm.tqdm(
|
||||||
pool.imap_unordered(_process_and_match, work_pkgs),
|
pool.imap_unordered(_process_and_match, work_pkgs),
|
||||||
|
@ -70,11 +70,15 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
|||||||
# with postgres.
|
# with postgres.
|
||||||
db.connections.close_all()
|
db.connections.close_all()
|
||||||
|
|
||||||
with multiprocessing.Pool(processes=self.process_count) as pool:
|
if self.process_count == 1:
|
||||||
list(
|
for doc_id in ids:
|
||||||
tqdm.tqdm(
|
_process_document(doc_id)
|
||||||
pool.imap_unordered(_process_document, ids),
|
else: # pragma: no cover
|
||||||
total=len(ids),
|
with multiprocessing.Pool(processes=self.process_count) as pool:
|
||||||
disable=self.no_progress_bar,
|
list(
|
||||||
),
|
tqdm.tqdm(
|
||||||
)
|
pool.imap_unordered(_process_document, ids),
|
||||||
|
total=len(ids),
|
||||||
|
disable=self.no_progress_bar,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@ -36,7 +36,7 @@ class TestArchiver(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"),
|
os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"),
|
||||||
)
|
)
|
||||||
|
|
||||||
call_command("document_archiver")
|
call_command("document_archiver", "--processes", "1")
|
||||||
|
|
||||||
def test_handle_document(self):
|
def test_handle_document(self):
|
||||||
doc = self.make_models()
|
doc = self.make_models()
|
||||||
|
@ -83,13 +83,13 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
def test_command(self):
|
def test_command(self):
|
||||||
self.assertIsNotFile(self.d1.thumbnail_path)
|
self.assertIsNotFile(self.d1.thumbnail_path)
|
||||||
self.assertIsNotFile(self.d2.thumbnail_path)
|
self.assertIsNotFile(self.d2.thumbnail_path)
|
||||||
call_command("document_thumbnails")
|
call_command("document_thumbnails", "--processes", "1")
|
||||||
self.assertIsFile(self.d1.thumbnail_path)
|
self.assertIsFile(self.d1.thumbnail_path)
|
||||||
self.assertIsFile(self.d2.thumbnail_path)
|
self.assertIsFile(self.d2.thumbnail_path)
|
||||||
|
|
||||||
def test_command_documentid(self):
|
def test_command_documentid(self):
|
||||||
self.assertIsNotFile(self.d1.thumbnail_path)
|
self.assertIsNotFile(self.d1.thumbnail_path)
|
||||||
self.assertIsNotFile(self.d2.thumbnail_path)
|
self.assertIsNotFile(self.d2.thumbnail_path)
|
||||||
call_command("document_thumbnails", "-d", f"{self.d1.id}")
|
call_command("document_thumbnails", "--processes", "1", "-d", f"{self.d1.id}")
|
||||||
self.assertIsFile(self.d1.thumbnail_path)
|
self.assertIsFile(self.d1.thumbnail_path)
|
||||||
self.assertIsNotFile(self.d2.thumbnail_path)
|
self.assertIsNotFile(self.d2.thumbnail_path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user