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 (
HTTPServerRequest(protocol='http', host='', method='GET', uri='/ws', version='HTTP/1.1', remote_ip='')
Traceback (most recent call last):
  File "", line 647, in _run_callback
    result = callback(*args, **kwargs)
  File "", line 200, in on_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.