Is there any more information you could provide? Typically a “connection has been closed” error is merely a symptom of something else going on. Most commonly it is a misconfiguration on the connection.
Are you following something from the docs? Perhaps Build a Python App with CockroachDB and psycopg2 | CockroachDB Docs?