Skip to main content

Simple C++ ::std::this_thread::yield() call for Python, when sleep() calls have unknown effects.

Project description

pyyield: For when you don't know what time.sleep() does.

Keeping it at simple as possible, pyyield is a simple Python module build from C++ and executes 1 line of code:

::std::this_thread::yield()

The only reason for creating this was due to the inconsistencies when using time.sleep(), which until recently was not very well documented to how it's supposed to work when using with 0 or a small float, where some implementations don't seem to do anything on 0 and other implementations round up very small floats.

That is not to say the C++ yield is always the same either, but for that, read more

Usage:

Example usage, yield from a loop

from pyyield import pyyield

def workerLoop():
    while performSomeWork():
        pyyield()

Build and install from source:

pip install -r requirements.txt
python -m build -o ./dist
pip install ./dist/pyyield*.whl

Tests

pip install pytest        
pytest --verbose --log-cli-level=DEBUG

The tests are mainly there to make an extremely simple check of performance differences. Please change the tests and play around with it yourself to understand how it performs on the system you want to run it on!

For example, as of writing this, in GitHub Actions, ubuntu-latest, pyyield does not perform any better than sleep(0) on all python versions tested, printing the info:

Failed to at speed test: pyyield is not faster than sleep(0)!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyyield-0.1.0.tar.gz (40.7 kB view hashes)

Uploaded Source

Built Distributions

pyyield-0.1.0-cp312-cp312-win_amd64.whl (31.8 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pyyield-0.1.0-cp312-cp312-manylinux2014_x86_64.whl (44.9 kB view hashes)

Uploaded CPython 3.12

pyyield-0.1.0-cp312-cp312-macosx_10_9_universal2.whl (31.1 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

pyyield-0.1.0-cp311-cp311-win_amd64.whl (31.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyyield-0.1.0-cp311-cp311-manylinux2014_x86_64.whl (44.9 kB view hashes)

Uploaded CPython 3.11

pyyield-0.1.0-cp311-cp311-macosx_10_9_universal2.whl (31.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

pyyield-0.1.0-cp310-cp310-win_amd64.whl (31.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyyield-0.1.0-cp310-cp310-manylinux2014_x86_64.whl (44.9 kB view hashes)

Uploaded CPython 3.10

pyyield-0.1.0-cp310-cp310-macosx_10_9_universal2.whl (31.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyyield-0.1.0-cp39-cp39-win_amd64.whl (31.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyyield-0.1.0-cp39-cp39-manylinux2014_x86_64.whl (44.7 kB view hashes)

Uploaded CPython 3.9

pyyield-0.1.0-cp39-cp39-macosx_10_9_universal2.whl (31.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page