Skip to content

Background thread is created on library import #796

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

Closed
martinhanzik opened this issue May 31, 2025 · 1 comment · Fixed by #804
Closed

Background thread is created on library import #796

martinhanzik opened this issue May 31, 2025 · 1 comment · Fixed by #804
Labels
bug Something isn't working

Comments

@martinhanzik
Copy link

Describe the bug

A background thread is created when the library is imported. This thread is used for tracing and having tracing disabled has no effect on this, as it is evaluated after the thread creation.

This is in my opinion quite bad and it causes issues in our environment, where we use process-based parallelization and require no extra threads to be running at the startup of the program. I am working around this by importing anything from the agents library inside my functions, not in the global file scope. Not ideal though.

Debug information

  • Agents SDK version: 0.0.16
  • Python version: Python 3.13

Repro steps

import threading
assert threading.active_count() == 1
import agents
assert threading.active_count() == 1

Expected behavior

My expectation would be, that the thread will be created either explicitly, or when needed - for example when the first Runner.run is called, or some tracing functionality is explicitly used for the first time.

@martinhanzik martinhanzik added the bug Something isn't working label May 31, 2025
@martinhanzik martinhanzik changed the title Background threads are created on library import Background thread is created on library import May 31, 2025
@rm-openai
Copy link
Collaborator

Yeah, makes sense. Will fix.

rm-openai added a commit that referenced this issue Jun 2, 2025
Closes #796. Shouldn't start a busy waiting thread if there aren't any
traces.

Test plan
```
import threading
assert threading.active_count() == 1
import agents
assert threading.active_count() == 1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants