Hi,
I'm trying to cleanly dispose an SQLAlchemy engine at uWSGI worker exit, by
doing this:
def dispose_dbengine():
print 'in dispose_dbengine'
try:
if uwsgi:
uwsgi.lock()
print 'uwsgi locked in %s' % os.getpid()
print 'disposing engine %s' % id(engine)
try:
engine.dispose()
except BaseException, exc:
print '... dispose failed'
traceback.print_exc()
else:
print '... engine disposed'
finally:
if uwsgi:
uwsgi.unlock()
print 'uwsgi unlocked in %s' % os.getpid()
import uwsgi
uwsgi.atexit = dispose_dbengine
When I stop uwsgi by sending SIGINT to the master process, this seems to work,
except that it seems to run atexit twice in each worker process (which is OK
for my case specifically, but probably a problem for some uses):
SIGINT/SIGQUIT received...killing workers...
in dispose_dbengine
in dispose_dbengine
uwsgi locked in 56957
disposing engine 4526637904
... engine disposed
uwsgi unlocked in 56957
uwsgi locked in 56958
disposing engine 4526641872
in dispose_dbengine
... engine disposed
uwsgi unlocked in 56958
uwsgi locked in 56957
disposing engine 4526637904
in dispose_dbengine
... engine disposed
uwsgi unlocked in 56957
uwsgi locked in 56958
disposing engine 4526641872
... engine disposed
uwsgi unlocked in 56958
goodbye to uWSGI.
But when I stop uwsgi using Ctrl-C in a console, the dispose doesn't complete,
no exception is caught, and the lock is not released:
^CSIGINT/SIGQUIT received...killing workers...
in dispose_dbengine
in dispose_dbengine
uwsgi locked in 57071
disposing engine 4475134672
[deadlock-detector] pid 57071 was holding lock user 0 (0x10968c000)
goodbye to uWSGI.
and I get "unexpected EOF on client connection" in my PostgreSQL log, showing
that the engine was indeed not cleanly disposed.
Is there a way to make Ctrl-C trigger a clean shutdown just like SIGINT to the
master?
Best regards,
Gulli
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi