=============
Polling is a powerful python utility used to wait for a function to return a certain expected condition.
Some possible uses cases include:
- Wait for API response to return with code 200
- Wait for a file to exist (or not exist)
- Wait for a thread lock on a resource to expire
# Installation
pip install polling
# Examples
### Example: Poll every minute until a url returns 200 status code
import requests
polling.poll(
lambda: requests.get('http://google.com').status_code == 200,
step=60,
poll_forever=True
)
### Example: Poll for a file to exist
# This call will wait until the file exists, checking every 0.1 seconds and stopping after 3 seconds have elapsed
file_handle = polling.poll(
lambda: open('/tmp/myfile.txt'),
ignore_exceptions=(IOError,),
timeout=3,
step=0.1
)
# Polling will return the value of your polling function, so you can now interact with it
file_handle.close()
### Example: Polling for Selenium WebDriver elements
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://google.com')
search_box = polling.poll(
lambda: driver.find_element_by_id('search'),
step=0.5,
timeout=7
)
search_box.send_keys('python polling')
### Example: Using the polling timeout exception
# An exception will be raised by the polling function on timeout (or the maximum number of calls is exceeded).
# This exception will have a 'values' attribute. This is a queue with all values that did not meet the condition.
# You can access them in the except block.
import random
try:
polling.poll(lambda: random.choice([0, (), False]), step=0.5, timeout=1)
except polling.TimeoutException, te:
while not te.values.empty():
# Print all of the values that did not meet the exception
print te.values.get()
### Example: Using a custom condition callback function
import requests
def is_correct_response(response):
"""Check that the response returned 'success'"""
return response == 'success'
polling.poll(
lambda: requests.put('http://mysite.com/api/user', data={'username': 'Jill'},
check_success=is_correct_response,
step=1,
timeout=10
)
Metadata
Release files for polling 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polling-0.2.0.tar.gz | 4.7 kB | Without provenance | Details for polling-0.2.0.tar.gz |
Release files / polling-0.2.0.tar.gz
| Download URL | polling-0.2.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
972414e7aaf0df16b9eadb41205e32d479c674e3bb9b57ab561ceb5a0c594c51
|
|
BLAKE2b-256 checksum How to use checksums |
ef105207cd5bd1c80a6f2959b56ede06806165a122766e1765f6c83db3ef1dad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for polling 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.