You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using bravado's SwaggerClient in a multiprocessing protocol causes a RecursionError.
Example
Code for minimal example:
from multiprocessing import Pool
from bravado.client import SwaggerClient
API_DEFINITIONS = "https://klifs.net/swagger/swagger.json"
CLIENT = SwaggerClient.from_url(API_DEFINITIONS, config={"validate_responses": False})
pool = Pool(processes=2)
type_list = pool.map(type, [CLIENT, CLIENT])
print(type_list)
pool.close()
pool.join()
Output:
Process ForkPoolWorker-2:
Traceback (most recent call last):
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/multiprocessing/pool.py", line 114, in worker
task = get()
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/multiprocessing/queues.py", line 358, in get
return _ForkingPickler.loads(res)
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/site-packages/bravado/client.py", line 170, in __getattr__
return self._get_resource(item)
return self._get_resource(item)
File "/home/dominique/.local/miniconda/envs/kissim/lib/python3.8/site-packages/bravado/client.py", line 148, in _get_resource
resource = self.swagger_spec.resources.get(item)
# Repeating the line 170 and 148 errors over and over again
RecursionError: maximum recursion depth exceeded
Potential solution
Add serialization protocol in SwaggerClient by defining __getstate__ and __setstate.
@dominiquesydow thanks for reporting the issue. It would be great if you could open a PR yourself especially considering that you have found a way to address the issue.
Having such change would allow us to pass the SwaggerClient into a process Pool but more in general would allow us to pickle/unpickle the client (which might time consuming for big swagger specs)
Issue
Using
bravado
'sSwaggerClient
in a multiprocessing protocol causes aRecursionError
.Example
Code for minimal example:
Output:
Potential solution
Add serialization protocol in
SwaggerClient
by defining__getstate__
and__setstate
.@jaimergp managed to solve the problem in our
opencadd
package by implementing such a serialization protocol in aSerializationSwaggerClient
subclass. Maybe something like this could be added directly to theSwaggerClient
class?The text was updated successfully, but these errors were encountered: