Maximum recursion exception when using `reload`

16 views
Skip to first unread message

Alex Ge

unread,
Feb 21, 2022, 7:56:54 AMFeb 21
to MongoEngine Users
Hello, 
I'm using MongoEngine extensively in my project. One of the classes is an API handler that tracks how many calls I've made, when was the last one, etc.
It is being called by separate python processes that live in a different space. One of them (the most frequently called one)  has thrown this exception, which seems to originates from pymongo, and AFAIK relates to locking and unlocking a semaphore:

```
maximum recursion depth exceeded while calling a Python object
Traceback (most recent call last):
File "/root/oneshot/core/apicallers.py", line 28, in wrapper
return func(*args, **kwargs)
File "/root/oneshot/core/apicallers.py", line 287, in __call__
self.add_call()
File "/root/oneshot/core/apicallers.py", line 103, in add_call
self.counter.reload()
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/document.py", line 726, in reload
self._qs.read_preference(ReadPreference.PRIMARY)
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/queryset/base.py", line 836, in select_related
return queryset._dereference(queryset, max_depth=max_depth)
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/dereference.py", line 37, in __call__
items = [i for i in items]
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/dereference.py", line 37, in <listcomp>
items = [i for i in items]
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/queryset/queryset.py", line 110, in _iter_results
self._populate_cache()
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/queryset/queryset.py", line 129, in _populate_cache
self._result_cache.append(next(self))
File "/root/oneshot/venv/lib/python3.8/site-packages/mongoengine/queryset/base.py", line 1565, in __next__
raw_doc = next(self._cursor)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1156, in next
if len(self.__data) or self._refresh():
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 1073, in _refresh
self.__send_message(q)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/cursor.py", line 953, in __send_message
response = client._run_operation_with_response(
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1342, in _run_operation_with_response
return self._retryable_read(
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1464, in _retryable_read
return func(session, server, sock_info, slave_ok)
File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
next(self.gen)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1285, in _slaveok_for_server
yield sock_info, slave_ok
File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
next(self.gen)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1230, in _get_socket
yield sock_info
File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
next(self.gen)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/pool.py", line 1153, in get_socket
self.return_socket(sock_info)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/pool.py", line 1227, in return_socket
self._socket_semaphore.release()
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/thread_util.py", line 86, in release
return Semaphore.release(self)
File "/root/oneshot/venv/lib/python3.8/site-packages/pymongo/thread_util.py", line 66, in release
self._cond.notify()
File "/usr/lib/python3.8/threading.py", line 351, in notify
if not self._is_owned():
File "/usr/lib/python3.8/threading.py", line 264, in _is_owned
if self._lock.acquire(0):
RecursionError: maximum recursion depth exceeded while calling a Python object
```

Any ideas how to fit this, or alternatively how to avoid it?
Reply all
Reply to author
Forward
0 new messages