_pickle.PicklingError: cannot pickle '_thread.lock' object

Hello Community,

I have developed a RAG Chatbot locally (Code can be found here: PrototypGrundschutzChatbot - a Hugging Face Space by MikeMann).

Everything works fine on my local machine, but when i move it to spaces and ask a question I get the following error:

Traceback (most recent call last):
File “/usr/local/lib/python3.10/site-packages/gradio/queueing.py”, line 624, in process_events
response = await route_utils.call_process_api(
File “/usr/local/lib/python3.10/site-packages/gradio/route_utils.py”, line 323, in call_process_api
output = await app.get_blocks().process_api(
File “/usr/local/lib/python3.10/site-packages/gradio/blocks.py”, line 2043, in process_api
result = await self.call_function(
File “/usr/local/lib/python3.10/site-packages/gradio/blocks.py”, line 1602, in call_function
prediction = await utils.async_iteration(iterator)
File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 710, in async_iteration
return await anext(iterator)
File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 704, in anext
return await anyio.to_thread.run_sync(
File “/usr/local/lib/python3.10/site-packages/anyio/to_thread.py”, line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
File “/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py”, line 2505, in run_sync_in_worker_thread
return await future
File “/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py”, line 1005, in run
result = context.run(func, *args)
File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 687, in run_sync_iterator_async
return next(iterator)
File “/usr/local/lib/python3.10/site-packages/gradio/utils.py”, line 848, in gen_wrapper
response = next(iterator)
File “/home/user/app/app.py”, line 443, in gradiobot
bot_response = bot.ragPrompt(history[-1].get(‘content’), reranking, history)
File “/usr/local/lib/python3.10/site-packages/spaces/zero/wrappers.py”, line 202, in gradio_handler
worker.arg_queue.put(((args, kwargs), GradioPartialContext.get()))
File “/usr/local/lib/python3.10/site-packages/spaces/utils.py”, line 51, in put
raise PicklingError(message)
_pickle.PicklingError: cannot pickle ‘_thread.lock’ object

Do you have any hints or ideas for me? Thank you in advance.

1 Like

This looks like a Zero GPU space-related error. You’re more likely to get a reliable response by asking in the community below.
In general, you should expect functions with spaces decorators to behave in rather unusual ways.
In particular, asynchronous, multi-threaded, multi-process, global variables, and class methods can be troublesome.

1 Like

Thank you @John6666! I will ask my question there and have a deeper lock into asynchronous behaviour!

1 Like