Created
March 13, 2026 11:11
-
-
Save methane/8bc735c373747fe9c5d57c5f12eadf69 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
| # /// script | |
| # requires-python = ">=3.14" | |
| # dependencies = [ | |
| # "niquests>=3.18.2", | |
| # ] | |
| # /// | |
| import niquests | |
| from niquests.adapters import HTTPAdapter | |
| import threading | |
| import time | |
| import sys | |
| import logging | |
| import faulthandler | |
| logging.basicConfig( | |
| level=logging.DEBUG, format="%(asctime)s %(threadName)s %(levelname)s %(message)s" | |
| ) | |
| logger = logging.getLogger("niquests_block") | |
| session = niquests.Session(pool_maxsize=1) | |
| def get_worker(): | |
| for _ in range(4): | |
| try: | |
| response = session.get(f"http://localhost:3001/delay/2") | |
| response.raise_for_status() | |
| except Exception as e: | |
| logger.exception("request failed: %s", e) | |
| time.sleep(0.2) | |
| def main(): | |
| threads = [] | |
| for i in range(2): | |
| t = threading.Thread(target=get_worker, name=f"worker-{i}") | |
| t.start() | |
| threads.append(t) | |
| #for _ in range(7): | |
| # faulthandler.dump_traceback() | |
| # time.sleep(1) | |
| for t in threads: | |
| t.join() | |
| pools = session.adapters["http://"].poolmanager.pools | |
| print(f"{pools.maxsize=}, {pools.concurrency=}, {pools.strict_maxsize=}") | |
| if __name__ == "__main__": | |
| main() |
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
| # /// script | |
| # requires-python = ">=3.14" | |
| # dependencies = [ | |
| # "requests>=2.32.5", | |
| # ] | |
| # /// | |
| import requests | |
| from requests.adapters import HTTPAdapter | |
| import threading | |
| import time | |
| import sys | |
| import logging | |
| logging.basicConfig( | |
| level=logging.DEBUG, format="%(asctime)s %(threadName)s %(levelname)s %(message)s" | |
| ) | |
| logger = logging.getLogger("requests_block") | |
| session = requests.Session() | |
| session.mount("http://", HTTPAdapter(pool_maxsize=1, pool_block=False)) | |
| session.mount("https://", HTTPAdapter(pool_maxsize=1, pool_block=False)) | |
| def get_worker(): | |
| for _ in range(4): | |
| try: | |
| response = session.get(f"http://localhost:3001/delay/2") | |
| response.raise_for_status() | |
| except Exception as e: | |
| logger.exception("request failed: %s", e) | |
| time.sleep(0.2) | |
| def main(): | |
| threads = [] | |
| for i in range(2): | |
| t = threading.Thread(target=get_worker, name=f"worker-{i}") | |
| t.start() | |
| threads.append(t) | |
| for t in threads: | |
| t.join() | |
| if __name__ == "__main__": | |
| main() |
Author
methane
commented
Mar 13, 2026
Author
Before run these scripts, you need to run:
docker run -p 127.0.0.1:3001:80 kennethreitz/httpbin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment