Baltic-RCC / EMF

Repository for Open Source EMF implementation
Mozilla Public License 2.0
8 stars 3 forks source link

Model retriver connection gets "Transport indicated EOF" #134

Open VeikoAunapuu opened 1 month ago

VeikoAunapuu commented 1 month ago

Issue seems to be size of the models or connetion stability.

Possible solution proposed threading: https://stackoverflow.com/questions/58927722/pika-connection-lost-error-pika-exceptions-streamlosterror-stream-connection-l

Sample: https://github.com/pika/pika/blob/1.0.1/examples/basic_consumer_threaded.py

VeikoAunapuu commented 1 month ago

Target solution is: t = threading.Thread(target=do_work, args=(conn, ch, delivery_tag, body)) t.start() thrds.append(t)

Move merging work to thread and keep rabbitMQ on main (sample proposal): import threading import time

Define a function to be run in a separate thread

def worker(event, status): print("Worker thread starting...") time.sleep(5) # Simulate a long-running process status["message"] = "Worker thread finished" print("Worker thread finished.") event.set() # Signal that the thread has finished

Main function

def main(): status = {"message": "Worker thread not started"} event = threading.Event()

# Create a thread to run the worker function
thread = threading.Thread(target=worker, args=(event, status))
thread.start()

print("Main thread is waiting for the worker thread to finish...")

# Wait for the event to be set by the worker thread
event.wait()

print("Main thread detected worker thread finished.")
print(f"Status: {status['message']}")

if name == "main": main()

Haigutus commented 1 month ago

I would go with something like this


from concurrent.futures import ThreadPoolExecutor
import time

def do_work(ch, delivery_tag, body):
    # Simulate some work with sleep
    time.sleep(5)
    return f"Processed: {body}"

# Create a ThreadPoolExecutor
with ThreadPoolExecutor() as executor:
    # Submit the work to the executor
    future = executor.submit(do_work, ch, delivery_tag, body)

    # Perform other tasks here if necessary

    # Retrieve the result
    while not future.done():
        print("Thread is still running...")
        time.sleep(1)

    output = future.result()

print("Thread has finished.")
print("Output:", output)
Haigutus commented 1 week ago

Waiting for external support