From 107ef803d4e046c4fa65105728d0fe8c6fbc08e4 Mon Sep 17 00:00:00 2001 From: Rossen <2720787+rossengeorgiev@users.noreply.github.com> Date: Sun, 3 Oct 2021 20:19:00 +0100 Subject: [PATCH] Remove gevent monkey patch by default in steam.client (#364) * remove gevent monkey patch by default in steam.client * add entry to changelog --- CHANGES.md | 8 ++++++++ docs/api/steam.client.monkey.rst | 7 +++++++ docs/user_guide.rst | 4 ++++ steam/client/__init__.py | 10 +++++----- steam/client/cdn.py | 11 +++++++++++ steam/client/monkey.py | 26 ++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 docs/api/steam.client.monkey.rst create mode 100644 steam/client/monkey.py diff --git a/CHANGES.md b/CHANGES.md index e6fcbbb2..7ef6b40d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/docs/api/steam.client.monkey.rst b/docs/api/steam.client.monkey.rst new file mode 100644 index 00000000..9bb23b55 --- /dev/null +++ b/docs/api/steam.client.monkey.rst @@ -0,0 +1,7 @@ +monkey +====== + +.. automodule:: steam.client.monkey + :members: + :show-inheritance: + diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 0389d389..d53a3a75 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -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 ----------- diff --git a/steam/client/__init__.py b/steam/client/__init__.py index aa837602..ec6a1941 100644 --- a/steam/client/__init__.py +++ b/steam/client/__init__.py @@ -1,6 +1,11 @@ """ 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. @@ -8,11 +13,6 @@ 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 diff --git a/steam/client/cdn.py b/steam/client/cdn.py index 568f1889..b124086e 100644 --- a/steam/client/cdn.py +++ b/steam/client/cdn.py @@ -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) diff --git a/steam/client/monkey.py b/steam/client/monkey.py new file mode 100644 index 00000000..60f3091c --- /dev/null +++ b/steam/client/monkey.py @@ -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()