Timeouts for popular Python packages

Overview

Python Timeouts

An unresponsive service can be worse than a down one. It can tie up your entire system if not handled properly. All network requests should have a timeout.

Here’s how to add timeouts for popular Python packages. All have been tested. The default is no timeout, unless otherwise specified. Enjoy!

Build Status

Packages

Standard library

PyPI

Standard Library

http

HTTPConnection(host, port, timeout=1)

Raises socket.timeout

smtplib

SMTP(host, timeout=1)

Raises

  • socket.timeout on connect timeout
  • smtplib.SMTPServerDisconnected on read timeout

socket

sock.settimeout(1)

Raises socket.timeout

subprocess

subprocess.run(cmd, timeout=1)

Raises subprocess.TimeoutExpired

PyPI

aiohttp

timeout = aiohttp.ClientTimeout(total=1)
async with aiohttp.ClientSession(timeout=timeout) as session:
    # ...

Raises asyncio.exceptions.TimeoutError

asyncpg

asyncpg.connect(timeout=1)

Default: 60s

Raises asyncio.exceptions.TimeoutError

boto3

boto3.client('s3', config=Config(connect_timeout=1, read_timeout=1))

Raises

  • botocore.exceptions.ConnectTimeoutError on connect timeout
  • botocore.exceptions.ReadTimeoutError on read timeout

elasticsearch

Elasticsearch(timeout=1)

Raises elasticsearch.exceptions.ConnectionError

mongoengine

connect(connectTimeoutMS=1000, socketTimeoutMS=1000, serverSelectionTimeoutMS=1000)

Raises pymongo.errors.ServerSelectionTimeoutError

mysqlclient

MySQLdb.connect(connect_timeout=1)

Raises MySQLdb._exceptions.OperationalError

opensearch-py

OpenSearch(timeout=1)

Raises opensearchpy.exceptions.ConnectionError

psycopg

psycopg.connect(connect_timeout=1)

Raises psycopg.OperationalError

psycopg2

psycopg2.connect(connect_timeout=1)

Raises psycopg2.OperationalError

pymemcache

Client(host, connect_timeout=1, timeout=1)

Raises socket.timeout

pymongo

MongoClient(connectTimeoutMS=1000, socketTimeoutMS=1000, serverSelectionTimeoutMS=1000)

Default: 20s connect timeout, 30s server selection timeout

Raises pymongo.errors.ServerSelectionTimeoutError

redis

Redis(socket_connect_timeout=1, socket_timeout=1)

Raises redis.exceptions.TimeoutError

requests

requests.get(url, timeout=1)

Raises

  • requests.exceptions.ConnectTimeout on connect timeout
  • requests.exceptions.ReadTimeout on read timeout

SQLAlchemy

create_engine(url, connect_args={'connect_timeout': 1})

Raises sqlalchemy.exc.OperationalError

Don’t see a library you use?

Let us know. Even better, create a pull request for it.

Running the Tests

git clone https://github.com/ankane/python-timeouts.git
cd python-timeouts
pip install -r requirements.txt

To run all tests, use:

pytest

To run individual tests, use:

pytest tests/test_redis.py
Owner
Andrew Kane
Andrew Kane
ip2domain - get ip to domain, Know the domian corresponding to the local network connection IP

What is Sometimes, we need to know what connections our local machine has, and what are their IP, domain name, program and parameters? get ip to domai

51pwn 4 Sep 30, 2022
A library for interacting with APNs and VoIP using HTTP/2.

kalyke A library for interacting with APNs and VoIP using HTTP/2. Installation kalyke requires python 3.6 or later. $ pip install kalyke-apns Usage AP

Yuya Oka 11 Dec 08, 2022
The OUCH Project - OUCH Server/Client

This software simulates OUCH Server/Client communication through a script which initialises a central server and another script which simulates clients connecting to the server.

Jahin Z. 2 Dec 10, 2022
Uses machine learning to scan the similarity of two texts

PlagiarismChecker Uses machine learning to scan the similarity of two documents. End Points: http://localhost:3000/register (create a/c) http://localh

Elvis Chege 2 Aug 10, 2022
The can package provides controller area network support for Python developers

python-can The Controller Area Network is a bus standard designed to allow microcontrollers and devices to communicate with each other. It has priorit

Brian Thorne 904 Dec 29, 2022
euserv auto-renew script - A Python script which can help you renew your free EUserv IPv6 VPS.

eu_ex eu_ex means EUserv_extend. A Python script which can help you renew your free EUserv IPv6 VPS. This Script can check the VPS amount in your acco

A beam of light 92 Jan 25, 2022
Simplest dashboard for WireGuard VPN written in Python w/ Flask

Hi! I'm planning the next major update for this project, please let me know if you have any suggestions or feature requests ;) You can create an issue

Donald Zou 763 Jan 02, 2023
Socialhome is best described as a federated personal profile with social networking functionality

Description Socialhome is best described as a federated personal profile with social networking functionality. Users can create rich content using Mar

Jason Robinson 332 Dec 30, 2022
Makes dynamically updating your Cloudflare DNS records a bit easier ⏩👍😎

Easy Dynamic Cloudflare DNS Updater Makes dynamically updating your Cloudflare DNS records a bit easier ⏩ 👍 😎 If using it as a 'Dynamic DNS' client,

Zac Koch 3 Dec 19, 2021
A gRPC-Web implementation for Python

Sonora Sonora is a Python-first implementation of gRPC-Web built on top of standard Python APIs like WSGI and ASGI for easy integration. Why? Regular

Alex Stapleton 216 Dec 30, 2022
Search ports in multiples hosts

Search Port ✨ Multiples Searchs ✨ Create list hosts Create list targets Start Require Python 3.10.0+. python main.py Struture Function Directory load_

Tux#3634 7 Apr 29, 2022
Docker container for demoing Wi-Fi calling stack.

VoWiFiLocalDemo - Docker container that runs StrongSwan and Kamailio to demonstrate how Wi-Fi calling works on smartphones.

18 Nov 12, 2022
Base on browser-time to get har from network, and use python to analyze the data .

base on browser-time to get har from network, and use python to analyze the data

1 Dec 20, 2021
Multiple-requests-poster - A tool to send multiple requests to a particular website written in Python

Multiple-requests-poster - A tool to send multiple requests to a particular website written in Python

RLX 2 Feb 14, 2022
Throttle rTorrent on Plex stream Start/Stop

Dependencies Python 3.6+ Tautulli Script Setup Edit rtorrent_throttle.py and set rTorrent username, password and RPC2 url. Tautulli Setup Commum Scrip

4 Apr 25, 2022
The module that allows the collection of data sampling, which is transmitted with WebSocket via WIFI or serial port for CSV file.

The module that allows the collection of data sampling, which is transmitted with WebSocket via WIFI or serial port for CSV file.

Nelson Wenner 2 Apr 01, 2022
Publish GPU miner info to MQTT

Miner2MQTT Доступ к вашему GPU майнеру через MQTT. Изменения 1.0 EXE файл для Windows 1.1 Управление вентиляторами видеокарт (Linux) Упраление power l

Dmitry Bukhvalov 5 Aug 21, 2022
Malcolm is a powerful, easily deployable network traffic analysis tool suite for full packet capture artifacts (PCAP files) and Zeek logs.

Malcolm is a powerful, easily deployable network traffic analysis tool suite for full packet capture artifacts (PCAP files) and Zeek logs.

Cybersecurity and Infrastructure Security Agency 1.3k Jan 08, 2023
BibleNotifyDesktop - Desktop version of Bible Notify

Bible Notify Desktop This is the repository for the Desktop version of the daily

Bible Notify 5 Nov 16, 2022
this is demo of tool dosploit for test and dos in network with python

this tool for dos and pentest vul SKILLS: syn flood udp flood $ git clone https://github.com/amicheh/demo_dosploit/ $ cd demo_dosploit $ python3 -m pi

yaser amir chehrazi 5 Sep 22, 2022