Skip to content

Commit cb3523d

Browse files
Merge pull request #470 from OP-TED/feature/TED-1304
Update rml_mapper.py
2 parents e0cf5d5 + e294b62 commit cb3523d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

ted_sws/notice_transformer/adapters/rml_mapper.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import abc
2+
import os
3+
import signal
24
import subprocess
35
from enum import Enum
46
from pathlib import Path
@@ -91,8 +93,16 @@ def execute(self, package_path: Path) -> str:
9193
"""
9294
# java -jar ./rmlmapper.jar -m rml.ttl -s turtle -o output.ttl
9395
bash_script = f"cd {package_path} && java -jar {self.rml_mapper_path} -m {package_path / MS_TRANSFORM_FOLDER_NAME / MS_MAPPINGS_FOLDER_NAME / '*'} -s {self.get_serialization_format_value()}"
94-
script_result = subprocess.run(bash_script, shell=True, capture_output=True, timeout=self.transformation_timeout)
95-
error = script_result.stderr.decode('utf-8')
96+
process = subprocess.Popen(bash_script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
97+
if self.transformation_timeout:
98+
try:
99+
process.wait(timeout=self.transformation_timeout)
100+
except subprocess.TimeoutExpired as e:
101+
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
102+
raise e
103+
output, error = process.communicate()
104+
error = error.decode(encoding="utf-8")
96105
if error:
97106
raise Exception(error)
98-
return script_result.stdout.decode('utf-8')
107+
return output.decode(encoding="utf-8")
108+

0 commit comments

Comments
 (0)