diff --git a/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/compress_stringify.py b/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/compress_stringify.py index ca4a2c3e1..a40ff9753 100644 --- a/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/compress_stringify.py +++ b/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/compress_stringify.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -37,7 +39,9 @@ def compress_stringify( :return: Output compressed binary :rtype: bytes """ - pipeline = Pipeline(file_resources('itkwasm_compress_stringify_wasi').joinpath(Path('wasm_modules') / Path('compress-stringify.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_compress_stringify_wasi').joinpath(Path('wasm_modules') / Path('compress-stringify.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.BinaryStream), @@ -65,9 +69,7 @@ def compress_stringify( args.append(str(data_url_prefix)) - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = outputs[0].data.data return result diff --git a/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/parse_string_decompress.py b/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/parse_string_decompress.py index f4c2b93a7..592484386 100644 --- a/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/parse_string_decompress.py +++ b/packages/compress-stringify/python/itkwasm-compress-stringify-wasi/itkwasm_compress_stringify_wasi/parse_string_decompress.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -29,7 +31,9 @@ def parse_string_decompress( :return: Output decompressed binary :rtype: bytes """ - pipeline = Pipeline(file_resources('itkwasm_compress_stringify_wasi').joinpath(Path('wasm_modules') / Path('parse-string-decompress.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_compress_stringify_wasi').joinpath(Path('wasm_modules') / Path('parse-string-decompress.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.BinaryStream), @@ -49,9 +53,7 @@ def parse_string_decompress( args.append('--parse-string') - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = outputs[0].data.data return result diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/apply_presentation_state_to_image.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/apply_presentation_state_to_image.py index 18e1e96c1..fc96ce686 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/apply_presentation_state_to_image.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/apply_presentation_state_to_image.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -49,7 +51,9 @@ def apply_presentation_state_to_image( :return: Output image :rtype: Image """ - pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('apply-presentation-state-to-image.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('apply-presentation-state-to-image.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.JsonObject), @@ -84,9 +88,7 @@ def apply_presentation_state_to_image( args.append('--no-bitmap-output') - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = ( outputs[0].data.data, diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/read_dicom_encapsulated_pdf.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/read_dicom_encapsulated_pdf.py index a106aaa3b..bcdc163ab 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/read_dicom_encapsulated_pdf.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/read_dicom_encapsulated_pdf.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -86,7 +88,9 @@ def read_dicom_encapsulated_pdf( :return: Output pdf file :rtype: bytes """ - pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('read-dicom-encapsulated-pdf.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('read-dicom-encapsulated-pdf.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.BinaryStream), @@ -148,9 +152,7 @@ def read_dicom_encapsulated_pdf( args.append('--disable-correction') - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = outputs[0].data.data return result diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_html.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_html.py index 4a594c8ac..04b0d99e3 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_html.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_html.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -187,7 +189,9 @@ def structured_report_to_html( :return: Output text file :rtype: str """ - pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('structured-report-to-html.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('structured-report-to-html.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.TextStream), @@ -332,9 +336,7 @@ def structured_report_to_html( args.append('--code-details-tooltip') - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = outputs[0].data.data return result diff --git a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_text.py b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_text.py index 23b688d8a..9917fa3ae 100644 --- a/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_text.py +++ b/packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/structured_report_to_text.py @@ -6,6 +6,8 @@ from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -94,7 +96,9 @@ def structured_report_to_text( :return: Output text file :rtype: str """ - pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('structured-report-to-text.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('structured-report-to-text.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ PipelineOutput(InterfaceTypes.TextStream), @@ -162,9 +166,7 @@ def structured_report_to_text( args.append('--print-color') - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) result = outputs[0].data.data return result diff --git a/src/bindgen/python.js b/src/bindgen/python.js index 6b53b186c..11813ef76 100644 --- a/src/bindgen/python.js +++ b/src/bindgen/python.js @@ -278,6 +278,8 @@ from typing import Dict, Tuple, Optional, List from importlib_resources import files as file_resources +_pipeline = None + from itkwasm import ( InterfaceTypes, PipelineOutput, @@ -465,7 +467,9 @@ from itkwasm import ( moduleContent += `def ${functionName}( ${functionArgs}) -> ${returnType}: ${docstring} - pipeline = Pipeline(file_resources('${pypackage}').joinpath(Path('wasm_modules') / Path('${interfaceJson.name}.wasi.wasm'))) + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('${pypackage}').joinpath(Path('wasm_modules') / Path('${interfaceJson.name}.wasi.wasm'))) pipeline_outputs: List[PipelineOutput] = [ ${pipelineOutputs} ] @@ -474,9 +478,7 @@ ${pipelineOutputs} ] ${pipelineInputs} ] ${args} - outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs) - - del pipeline + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) ${postOutput} `