SSL error after python/django fork
database, django, fork, postgresql, python
Solution
Forking while holding a socket open (such as a database connection) is generally not safe, as both processes will end up trying to use the same socket at once.
You will need, at a minimum, to close and reopen the database connection after forking.
Ideally, though, this is probably better suited for a task queueing system like Celery.
Problem
I've got a python django app where part of it is parsing a large file. This takes forever, so I put a fork in to deal with the processing, allowing the user to continue to browse the site. Within the fork code, there's a bunch of calls to our postgres database, hosted on amazon. I'm getting the following error: ``` SSL error: decryption failed or bad record mac ``` Here's the code: ``` pid = os.fork() if pid == 0: lengthy_code_here(long) database_queries(my_database) os._exit(0) ``` None of my database calls are working, although they were working just fine before I inserted the fork. After looking around a little, it seems like it might be a stale database connection, but I'm not sure how to fix it. Does anyone have any ideas?