xai-org / xai-org/xai-sdk-python

[BUG] Blocking Synchronous I/O in Async Example Code (README.md)

Open Beginner friendly
#213 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
578
Forks
191
PR merge metrics
No merged PRs in 30d

Description

Confirmation of Issue Source
  • I confirm that this issue is with the xAI SDK Python library (e.g., client behavior, SDK methods, or documentation) and not with the xAI API itself (e.g., model output, API errors, or quota issues).
Describe the Bug

Location: README.md (Multi-Turn Chat Async example)

Issue: The Multi-Turn Chat (Asynchronous) code snippet uses standard blocking input() directly inside an async def main() function:

Steps to Reproduce
async def main():
    client = AsyncClient()
    ...
    while True:
        prompt = input("You: ")  # ❌ Blocks the entire asyncio event loop!
        ...

Expected Behavior

Main thread should not be blocked by any I/O operation.

Actual Behavior

Calling input() synchronously inside asyncio blocks the entire main thread event loop. Any background tasks, heartbeats, timers, or concurrent async requests scheduled on the loop will completely freeze until the user hits Enter.

xAI SDK Version

1.19.0

Python Version

3.10

Operating System

Windows 11

Client Type

Asynchronous Client (AsyncClient)

Code Snippet
Recommended Fix: Wrap input() in a thread executor
Error Messages or Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Multi-Turn Chat Asynchronous section in README.md and inspect how input() is called inside async def main(). Update the example so user input does not block the event loop, following the issue's recommended thread-executor approach. The work is done when the documented async example avoids synchronous blocking I/O.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.