Skip to main content

Puts code to sleep.

pypi badge downloads badge

Overview

The narcolepsy package contains code which alters the behavior of your application/api by injecting random sleep calls into decorated functions.

Usage

The following code is an example of using the @narcoleptic decorator.

from narcolepsy import narcoleptic

@narcoleptic(max=5)  # sleep for 5 seconds at max
def foobar():
    for x in xrange(1024):
        nested_function(x)

The @narcoleptic decorator takes three parameters (all optional):

  • min: The minimum sleep time in seconds.

  • max: The maximum sleep time in seconds.

  • chance: The maximum number of lines that will be executed before a sleep() call is injected.

If no min or max are passed in, the constants defined in narcolepsy.constants will be used instead. If no chance is passed in, a value will be derived from the number of lines in the input function.

Installation

The easiest way to install narcolepsy is via pip:

$ pip install narcolepsy

Known Issues

As mentioned in the official documentation, sys.settrace() isn’t part of the Python language definition and thus, may not be available to all Python implementations.

Why?

In theory this could help test time-critical code (multi-producer/consumer concurrent applications), but I mostly just wanted to play around with line tracers.

Disclaimer

This is a proof of concept and probably shouldn’t be used in any sort of real-world scenario where testing of time-critical code has any measure of importance. USE AT YOUR OWN RISK!

LICENSE

See the LICENSE file for details.

Metadata

Release files for narcolepsy 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for narcolepsy 0.0.3
File Size Uploaded
narcolepsy-0.0.3.tar.gz 4.4 kB Details

Release files / narcolepsy-0.0.3.tar.gz

Download URL narcolepsy-0.0.3.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5fa0f6da90950203980a4295ff4c53c34fdb84683d686001c15fb52e3a7be63b
BLAKE2b-256 checksum
How to use checksums
fff9dbe281ff720ea12ff6f74255c153e8476f92f4ebeb32382c5146ba4a8e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page