I use asyncio to write to mongo, using motor library.
When I have few bulk_writes, it works with no problem.
However, when I have many write in the same time, I get an exception RuntimeError: can't start new thread.
File "/usr/local/lib/python3.7/site-packages/motor/metaprogramming.py", line 77, in method **unwrapped_kwargs)
File "/usr/local/lib/python3.7/site-packages/motor/frameworks/asyncio/__init__.py", line 74 in run_on_executor
_EXECUTOR, functools.partial(fn, *args, **kwargs))
File "uvloop/loop.pyx", line 2702, in uvloop.loop.Loop.run_in_exector
File "/usr/local/lib/python3.7/concurrent/features/thread.py", line 160, in submit
self._adjust_thread_count()
File "/usr/local/lib/python3.7/concurrent/features/thread.py", line 181, in _adjust_thread_count
t.start()
File "usr/local/lib/python3.7/threading.py", line 847, in start
_start_new_thread(self._bootsrap, ())
RuntimeError: can't start new thread
I tried to change maxPoolSize, but it didn't work.
Important facts:
- In my local computer, it works with no errors. However, in
OpenshiftI have this problems. - In
OpenshiftI run my code via gunicorn viagunicorn app:app --worker-class uvicorn.workers.UvicornWorker - In
Openshift, when I have only oneworker, it works. But with 2+ worker I have this problem. - I don't open many connection of
AsyncIOMontorClient, I have only two at a time. - With
pymongowith almost the same code, I have no error, but there is noasynciosupport inpymongo. - Without the part of
mongo, my code works with no problems.