mirror of
https://github.com/langchain-ai/langchain-postgres.git
synced 2026-07-16 01:33:18 -04:00
BlockingError(func_name) when using engine = PGEngine.from_connection_string(url=connection_string) #77
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hypntzed78 on GitHub (Jun 24, 2025).
we dont have from_connection_string() for async method?
my code:
error:
` File "\Downloads\Project\chat-langchain.venv\Lib\site-packages\langchain_postgres\v2\engine.py", line 104, in from_connection_string
cls._default_loop = asyncio.new_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^
File "\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 810, in new_event_loop
return get_event_loop_policy().new_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 699, in new_event_loop
return self._loop_factory()
^^^^^^^^^^^^^^^^^^^^
File "\AppData\Local\Programs\Python\Python311\Lib\asyncio\selector_events.py", line 56, in init
self._make_self_pipe()
File "\AppData\Local\Programs\Python\Python311\Lib\asyncio\selector_events.py", line 107, in _make_self_pipe
self._ssock, self._csock = socket.socketpair()
^^^^^^^^^^^^^^^^^^^
File "\AppData\Local\Programs\Python\Python311\Lib\socket.py", line 645, in socketpair
ssock, _ = lsock.accept()
^^^^^^^^^^^^^^
File "Downloads\Project\chat-langchain.venv\Lib\site-packages\blockbuster\blockbuster.py", line 109, in wrapper
raise BlockingError(func_name)
blockbuster.blockbuster.BlockingError: Blocking call to socket.socket.accept
Heads up! LangGraph dev identified a synchronous blocking call in your code. When running in an ASGI web server, blocking calls can degrade performance for everyone since they tie up the event loop.
Here are your options to fix this:
Best approach: Convert any blocking code to use async/await patterns
For example, use 'await aiohttp.get()' instead of 'requests.get()'
Quick fix: Move blocking operations to a separate thread
Example: 'await asyncio.to_thread(your_blocking_function)'
Override (if you can't change the code):
`
@hypntzed78 commented on GitHub (Jun 24, 2025):
I have try with create() and create_sync(), both still block bluster
and
@averikitsch commented on GitHub (Jul 2, 2025):
Hi @ladylazy9x ,
from_connection_stringis not a blocking calling. You shouldn't need to use the asyncio.to_thread. That is handled for you in the implementation. I can not reproduce the error. Your code is running as expected.