ValvePython / steam

☁️ Python package for interacting with Steam
http://steam.readthedocs.io
MIT License
1.1k stars 137 forks source link

[BUG] Timeout with Threads #417

Closed 23cku0r closed 1 year ago

23cku0r commented 1 year ago

Description When i spawn threads, the TimeOut response is given

Steps to Reproduce the behavior

from multiprocessing.pool import ThreadPool
from steam.client import SteamClient

client = SteamClient()
client.set_credential_location("sentry_files/")
client.cli_login()

def get_player_count(app_id):
    return app_id, client.get_player_count(app_id)

with ThreadPool(5) as tp:
    results = tp.starmap(get_player_count, [(app_id,) for app_id in [730, 570, 578080, 4000, 1172470, 252490]])

# Output
# [(730, <EResult.Timeout: 16>),
#  (570, <EResult.Timeout: 16>),
#  (578080, <EResult.Timeout: 16>),
#  (4000, <EResult.Timeout: 16>),
#  (1172470, <EResult.Timeout: 16>),
#  (252490, <EResult.Timeout: 16>)]

Expected behavior

# Output
# [(730, 682296),
#  (570, 566814),
#  (578080, 192910),
#  (4000, 26759),
#  (1172470, 115724),
#  (252490, 99648)]

Versions Report

python -m steam.versions_report (Run python -m steam.versions_report and paste the output below) ```yaml steam: 1.4.3 Dependencies: vdf: 3.4 protobuf: 3.20.3 requests: 2.28.1 cachetools: 5.2.0 gevent: 22.10.2 gevent-eventemitter: 2.1 pycryptodomex: 3.16.0 enum34: Not Installed win-inet-pton: Not Installed Python runtime: executable: C:\Users\Andrew\PycharmProjects\steam_utils\venv\Scripts\python.exe version: 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] platform: win32 System info: system: Windows machine: AMD64 release: 10 version: 10.0.19045 ```
rossengeorgiev commented 1 year ago

The package is implemented with gevent which provided cooperative multitasking. You have two options:

  1. Monkeypatch threads to make them gevent cooperative
  2. Use gevent.pool.Pool (recommended)
23cku0r commented 1 year ago

Thanks!