> if__name__ =='__main__':
> main()|
>
> |
>
> This code works just fine, creating a pool of as many processes as I
> have CPU cores, and happily chugging along forever. I wanted to see how
> threads would compare to processes, but I could not get a working
> example. Here are the changes I made:
>
> |
>
> |fromconcurrent.futures importThreadPoolExecutoraspool
>
> session_maker =sa.orm.sessionmaker(bind=engine,autocommit=True)
> Session=sa.orm.scoped_session(session_maker)
>
>
> deftask(value):
> engine.dispose()
> # create new session per thread
> session =Session()
> withsession.begin():
> session.add(Example(text=value))
> # remove session once the work is done
> Session.remove()|
>
> |
>
> This version runs for a while before a flood of "too many clients"
> exceptions:
>
> |sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)FATAL:sorry,too
> many clients already|
>
>
> What's causing the problem?
it would appear that either the ThreadExecutorPool is starting more
threads than your Postgresql database has available connections, or your
engine.dispose() is leaving PG connections lying open to be garbage
collected. A single Engine should be all that's necessary in a single
process.
>
> --
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
sqlalchemy+...@googlegroups.com
> <mailto:
sqlalchemy+...@googlegroups.com>.
> To post to this group, send email to
sqlal...@googlegroups.com
> <mailto:
sqlal...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/sqlalchemy.
> For more options, visit
https://groups.google.com/d/optout.