Last active
April 2, 2025 07:42
-
-
Save Summertime/c6372209d0f7e23292cfba78d69abda2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeoutMixin: | |
def send(self, *args, **kwargs): | |
if hasattr(self, 'timeout') and 'timeout' not in kwargs: | |
kwargs['timeout'] = self.timeout | |
return super().send(*args, **kwargs) | |
# Use | |
import requests | |
class Session(TimeoutMixin, requests.Session): | |
pass | |
session = Session() | |
session.timeout = 120 | |
session.get('https://httpbin.org/get') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment