Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceWarning: unclosed transport when importing web_surfer #4821

Open
rickyloynd-microsoft opened this issue Dec 27, 2024 · 1 comment
Open
Milestone

Comments

@rickyloynd-microsoft
Copy link
Contributor

rickyloynd-microsoft commented Dec 27, 2024

What happened?

The attached (extremely simple) script invokes OpenAIChatCompletionClient and gets an appropriate response.

But on app shutdown a warning about "unclosed transport" is printed. As noted in the code, the warning disappears if the unused web_surfer import line is removed.

(ag3) rdlrdl@riloynd6:~/repos2/autogen/python/packages/autogen-ext/samples$ python warning_repro.py
Function calls again,
In endless looping layers—
Code within the code.
/home/rdlrdl/miniconda3/envs/ag3/lib/python3.10/asyncio/selector_events.py:710: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=6>
  _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

warning_repro.txt

import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import UserMessage

# The following import line leads to a warning about 'unclosed transport' on shutdown.
from autogen_ext.agents.web_surfer._utils import message_content_to_str

# The following line will do it too.
# from autogen_ext.agents.web_surfer import MultimodalWebSurfer


async def quick_test():
    client = OpenAIChatCompletionClient(
        model="gpt-4o-2024-08-06",
        api_key="")
    user_message = UserMessage(content="Write a haiku about recursion in programming.", source="user")
    response = await client.create([user_message])
    return response.content


if __name__ == "__main__":
    content = asyncio.run(quick_test())
    print(content)

What did you expect to happen?

Same behavior but without the warning.

How can we reproduce it (as minimally and precisely as possible)?

Install the following in a virtual environment:

pip install -e autogen-core      
pip install -e autogen-agentchat
pip install -e autogen-ext[openai]
pip install -e autogen-ext[web-surfer]

Run the attached code (after renaming the extension to .py, and supplying an api_key).

AutoGen version

0.4.0.dev11

Which package was this bug in

Core

Model used

gpt-4o-2024-08-06

Python version

3.10

Operating system

WSL2

Any additional info you think would be helpful for fixing this bug

No response

@brendanfoxen
Copy link

I'm having the exact same issue:

.pyenv/versions/3.10.13/lib/python3.10/asyncio/selector_events.py:710: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=10>
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)

Using Autogen 0.4.2
Python 3.10

@ekzhu ekzhu added this to the 0.4.x milestone Jan 18, 2025
@ekzhu ekzhu changed the title ResourceWarning: unclosed transport ResourceWarning: unclosed transport when importing web_surfer Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants