Skip to content

Commit

Permalink
Remove gevent monkey patch by default in steam.client (ValvePython#364)
Browse files Browse the repository at this point in the history
* remove gevent monkey patch by default in steam.client
* add entry to changelog
  • Loading branch information
rossengeorgiev authored Oct 3, 2021
1 parent f48192b commit 107ef80
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change notes

## 2.0.0

This release brings breaking changes

### steam.cleint

- Removed monkey patching by default. See `steam.client.monkey` for details

## 1.0.0

This release brings breaking changes
Expand Down
7 changes: 7 additions & 0 deletions docs/api/steam.client.monkey.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
monkey
======

.. automodule:: steam.client.monkey
:members:
:show-inheritance:

4 changes: 4 additions & 0 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ SteamClient
``gevent`` based implementation for interacting with the Steam network.
The library comes with some Steam client features implemented, see :doc:`api/steam.client` for more details.

.. warning::
:class:`.SteamClient` no longer applies gevent monkey patches by default.
See :mod:`steam.client.monkey` for details how make stdlib gevent cooperative.

CLI example
-----------

Expand Down
10 changes: 5 additions & 5 deletions steam/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Implementation of Steam client based on ``gevent``
.. warning::
``steam.client`` no longer patches stdlib to make it gevent cooperative.
This provides flexibility if you want to use :class:`.SteamClient` with async or other modules.
If you want to monkey patch anyway use :meth:`steam.client.monkey.patch_minimal()`
.. note::
Additional features are located in separate submodules. All functionality from :mod:`.builtins` is inherited by default.
.. note::
Optional features are available as :mod:`.mixins`. This allows the client to remain light yet flexible.
"""
import gevent
import gevent.monkey
gevent.monkey.patch_socket()
gevent.monkey.patch_ssl()

import os
import json
from random import random
Expand Down
11 changes: 11 additions & 0 deletions steam/client/cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
Initializing :class:`.CDNClient` requires a logged in :class:`.SteamClient` instance
.. warning::
This module uses :mod:`requests` library, which is not gevent cooperative by default.
It is high recommended that you use :meth:`steam.client.monkey.patch_minimal()`.
See example below
.. code:: python
import steam.client.monkey
steam.client.monkey.patch_minimal()
from steam.client import SteamClient, EMsg
from steam.client.cdn import CDNClient
mysteam = SteamClient()
mysteam.cli_login()
...
mycdn = CDNClient(mysteam)
Expand Down
26 changes: 26 additions & 0 deletions steam/client/monkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Helper moduel for calling ``gevent`` monkey patch functions.
This only need to if want to make stdlib gevent cooperative.
The patches need to be applied before any other module imports.
See :mod:`gevent.monkey` for details
.. code:: python
import steam.client.monkey
steam.client.monkey.patch_minimal()
import requests
from steam.client import SteamClient, EMsg
"""

def patch_minimal():
"""
This method needs to be called before any other imports
It calls :meth:`gevent.monkey.patch_socket()` and :meth:`gevent.monkey.patch_ssl()`
"""
import gevent.monkey
gevent.monkey.patch_socket()
gevent.monkey.patch_ssl()
gevent.monkey.patch_dns()

0 comments on commit 107ef80

Please sign in to comment.