crs4 / hl7apy

Python library to parse, create and handle HL7 v2 messages.
http://crs4.github.io/hl7apy/
MIT License
215 stars 85 forks source link

Multi-Threading support in HL7APY #95

Closed shamim40 closed 4 months ago

shamim40 commented 2 years ago

If multiple threads are trying to invoke hl7apy's parse_message(), each thread has it's own hl7 message, then it is crashing. If i add this under a thread lock, then multiple thread works with no issues, as below:

with threadLock: hl7_message = parse_message(hl7_data.replace('\n', '\r'), find_groups=False)

It seems to be parse_message() is not thread safe. If it is already fixed, then please provide in which version this has been fixed.

gcdsss commented 5 months ago

AttributeError: partially initialized module 'hl7apy.v2_4' has no attribute 'get' (most likely due to a circular import) this error occurred on multi-threading tcp server, looking forward to fix it.

svituz commented 4 months ago

finally released in 1.3.5

gcdsss commented 4 months ago

Hi, can you provide the details of the fix commit? I fixed it in my project just using threading lock, this it not a elegant way.

with threading.Lock():
     self.message = parse_message(
                        hl7_message,
                        find_groups=find_group,
                        validation_level=validation_level,
                    )
svituz commented 4 months ago

I just released the commit from this PR.