luigi icon indicating copy to clipboard operation
luigi copied to clipboard

SQLAlchemy concurrent DB access

Open K-Mike opened this issue 9 years ago • 5 comments

It appears that database access via SQLAlchemy (PyMySQL engine) gets broken if using more than 1 worker:

sqlalchemy.exc.OperationalError: (OperationalError) (2006, 'MySQL server has gone away'),
sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column 'table.id'",
etc...

Tried recommended multiprocessing guards: http://docs.sqlalchemy.org/en/rel_1_0/faq/connections.html#how-do-i-use-engines-connections-sessions-with-python-multiprocessing-or-os-fork

The standard multiprocessing implementation where each process calls a single task via luigi.build(…) works fine.

Any help would be greatly appreciated.

K-Mike avatar Aug 01 '17 15:08 K-Mike

I routinely use SQLAlchemy with 24 workers.

I'm connecting to Oracle, though it's not clear to me why that should matter.

Are you using the luigi --workers=2 CLI to create your workers? or something else?

dckc avatar Aug 28 '17 20:08 dckc

@K-Mike I'm dealing with the same problem. In our case I'm pretty sure is because we're sharing the Session object between the parent and the child processes and that don't work very well even calling the dispose method in Engine, re-creating the child processes session objects and so on.

ethervoid avatar Sep 21 '17 14:09 ethervoid

Running into the same problem working with a postgres database: when I use luigi --workers=2 I get

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL SYSCALL error: EOF detected

but when I omit the --worker argument altogether things work fine. Any hints?

tomsing1 avatar Jul 19 '18 01:07 tomsing1

I am getting a similar error for psycopg2. However, it says my tasks were successfully run. Were you able to find useful workarounds?

vruvora avatar Nov 07 '18 18:11 vruvora

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If closed, you may revisit when your time allows and reopen! Thank you for your contributions.

stale[bot] avatar Mar 07 '19 18:03 stale[bot]