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

KeyError in gradio_client stream_messages() pending_event_ids #10354

Open
1 task done
linzack opened this issue Jan 14, 2025 · 0 comments
Open
1 task done

KeyError in gradio_client stream_messages() pending_event_ids #10354

linzack opened this issue Jan 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@linzack
Copy link

linzack commented Jan 14, 2025

Describe the bug

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/gradio_client/client.py", line 277, in stream_messages
    self.pending_event_ids.remove(event_id)
KeyError: 'a4306ceb969b452f8b4e2d6de58cd88f'

Hi, a httpx.ReadTimeout during client.predict() might prevent self.client.pending_event_ids.add(event_id) from executing in make_predict().
This results in a missing event_id in pending_event_ids, causing the KeyError when stream_messages() attempts removal.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

from time import sleep
import httpx
from gradio_client import Client

client = Client(SPACE_NAME, HF_TOKEN)

while True:
    try:
        result = client.predict(
            state="0",
            api_name="/check_status"
        )
        if result:
            break
        else:
            sleep(60)
            continue
    except (httpx.ReadTimeout, httpx.ConnectError) as exc:
        print('this line executed when httpx.ReadTimeout')
        sleep(60)
        continue
    except Exception as exc:
        print('this line executed when pending_event_ids KeyError')
        break

Screenshot

No response

Logs

No response

System Info

print(gradio_client.__version__)
1.5.2

Severity

I can work around it

@linzack linzack added the bug Something isn't working label Jan 14, 2025
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

No branches or pull requests

1 participant