diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-15 16:09:40 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:26 +0100 |
commit | 621dd0d8c2c2c806ccf9632e049bcbf2a8f3a8e9 (patch) | |
tree | c238aeb5e9abbba5b7e707a3d28e1470ad8f179d | |
parent | 29511dd0454f59358e8c5f61964ffa0564fe99af (diff) | |
download | Ishtar-621dd0d8c2c2c806ccf9632e049bcbf2a8f3a8e9.tar.bz2 Ishtar-621dd0d8c2c2c806ccf9632e049bcbf2a8f3a8e9.zip |
migrate_to_geo_v4: add debug - monothread version do not use Pool
-rw-r--r-- | ishtar_common/management/commands/migrate_to_geo_v4.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ishtar_common/management/commands/migrate_to_geo_v4.py b/ishtar_common/management/commands/migrate_to_geo_v4.py index 498ec796a..e762bae94 100644 --- a/ishtar_common/management/commands/migrate_to_geo_v4.py +++ b/ishtar_common/management/commands/migrate_to_geo_v4.py @@ -21,6 +21,7 @@ from archaeological_finds.models import BaseFind from archaeological_warehouse.models import Warehouse, Container +debug = False log_path = os.sep.join([settings.ROOT_PATH, "logs"]) if not os.path.exists(log_path): os.mkdir(log_path, mode=0o770) @@ -73,6 +74,8 @@ cls_labels = { def _process_site_ope(obj): connection.close() + if debug: + base_debug = "_process_site_ope - l. {} - " + f"{obj} ({obj.pk}) - " + "{}" obj._no_move = True obj.skip_history_when_saving = True obj.save() # auto manage geo town association @@ -88,6 +91,8 @@ def _process_site_ope(obj): obj_verbose_names = cls_labels[obj.__class__.__name__] if obj.multi_polygon_source == "P" and obj.multi_polygon \ and obj.multi_polygon_source_item in obj_verbose_names: + if debug: + print(base_debug.format(95, "multi_polygon")) attrs = { "name": f"{_(model_name.capitalize())}{_(':')} {str(obj)}", "source_content_type": model_content_type, @@ -110,6 +115,8 @@ def _process_site_ope(obj): if obj.point_source == "P" and obj.point_2d \ and obj.point_source_item in obj_verbose_names: if obj.x and obj.y: + if debug: + print(base_debug.format(95, "point - coordinates")) attrs = { "name": f"{_(model_name.capitalize())}{_(':')} {str(obj)}", "source_content_type": model_content_type, @@ -132,6 +139,8 @@ def _process_site_ope(obj): ] ) elif obj.point_2d: + if debug: + print(base_debug.format(95, "point_2d")) attrs = { "name": f"{_(model_name.capitalize())}{_(':')} {str(obj)}", "source_content_type": model_content_type, @@ -258,11 +267,18 @@ def write_output(arg): def launch_job(lst, name, process_number, process_func): global idx, total, model_name, ref_time idx, total, model_name, ref_time = 0, len(lst), name, datetime.datetime.now() - pool = Pool(processes=process_number) + pool = None + if process_number > 1: + pool = Pool(processes=process_number) for item in lst: - pool.apply_async(process_func, (item,), callback=write_output) - pool.close() - pool.join() + if pool: + pool.apply_async(process_func, (item,), callback=write_output) + else: + process_func(item) + write_output(None) + if pool: + pool.close() + pool.join() quiet = False |