In our newest installation of “why you should not use Sybase SQL Anywhere” I’d like to report the latest problem I had to solve: for some reason, I couldn’t connect using sqlanydb from Celery tasks.

I had code that worked fine if ran from plain Python, but barfed from a celery worker task with the ominous error:

OperationalError: Failed to initialize connection object

Turns out, sqlanydb isn’t only not thread-safe; it’s also not fork-safe.

The possible solutions:

  1. Import the driver inside of your task function.
  2. Use on_worker_process_init() (untested).