> 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):

You mean that if you run 4 workers, atexit runs 8 times ?

> 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.
>
>

That is strange, which OS ?

-- 
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to