python – Agent-based simulation with MESA, tornado error: I/O operation on closed file

Good day,

I am running an agent-based simulation with MESA, and psycopg2 to save intermediate information to PostgreSQL.

When I run my simulation, it successfully iterates one time, however, the second iteration does not start due to the following error:

ERROR:tornado.application:Uncaught exception GET /ws (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8521', method='GET', uri='/ws', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "C:UsersUser.condaenvssiminvlibsite-packagestornadowebsocket.py", line 647, in _run_callback
    result = callback(*args, **kwargs)
  File "C:UsersUser.condaenvssiminvlibsite-packagesmesavisualizationModularVisualization.py", line 200, in on_message
    print(message)
ValueError: I/O operation on closed file.

The simulation model is large, thus it is difficult to provide a reproducible example. Currently, I am stuck, because I do not have ideas of what might cause this error. At the beginning of the simulation, I create a connection to the PostgreSQL database, and I do not close it during the simulation, thus this error should be related to the MESA framework. Any guidance would be appreciated.