
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Wait-For-It Python module, that waits until a certain TCP port is available.
Based on the idea behind the well-known wait-for-it script, but created mainly as a Python package to be used on other Python applications, services or modules, instead of being mainly a CLI tool.
Package is available at PyPi, so you can install it with pip install wait4it
-
or from sources with python setup.py install
.
from wait4it import wait_for, WaitForTimeoutError
# This should return instantly (if you have connection)
wait_for(host="google.com", port=80)
# This should fail in 5 seconds
try:
wait_for(host="google.com", port=12345, timeout=5)
except TimeoutError:
# Actually will raise custom WaitForTimeoutError exception, but inherits from TimeoutError (except on Python2)
print("Failed! (as expected)")
# This should return False in 15 seconds
wait_for(host="google.com", port=12345, raise_error=False)
# Normally you will want to check for a port in localhost (e.g. a MySQL/MariaDB database).
# This can be done directly like:
wait_for(3306)
# The exceptions include the failing host/port
try:
wait_for(host="google.com", port=12345)
except WaitForTimeoutError as ex:
assert ex.host == "google.com"
assert ex.port == 12345
It works similarly to wait_for, but if the considered exceptions are raised on the decorated function, it will re-run until it runs without raising these errors, or until the given retries limit is reached.
The following example will randomly raise ZeroDivisionError in the function divide_by_random
, which runs 10 times.
If fails more than twice, the exception will be thrown outside the function.
from random import randint
from wait4it import wait_for_pass
@wait_for_pass(ZeroDivisionError, retries=2)
def divide_by_random(n=10):
d = randint(0, 1)
print("Gonna divide", n, "/", d)
return n / d
for _ in range(10):
r = divide_by_random()
print("Got result:", r)
If retries
is set to 0, the function will run forever until it passes without raising exceptions.
wait_for_pass also allows a parameter retries_delay
, which can be used to define a delay, in seconds, between failed function executions.
Not external dependencies are required. Compatible (tested with) Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8 - under Linux.
FAQs
Wait until a certain TCP port is available
We found that wait4it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.