Skip to main content
https://travis-ci.org/flowroute/twisted-theseus.png

twisted-theseus

A Deferred-aware profiler for Python code.

While cProfile is a very useful utility, it is limited to recording synchronous execution time. A function that returns a Deferred will typically return very quickly, while the Deferred it returns might not fire for seconds or even minutes. This is where theseus comes in: any function that returns a Deferred will be tracked by theseus. The time from when the Deferred was returned to when it fired will be measured, and recorded along with the function’s call stack.

Usage

The public interface of theseus is a class called Tracer. To get started:

from theseus import Tracer
t = Tracer()
t.install()

This is enough to start tracing execution. Eventually, the statistics will have to be written to disk:

with open('callgrind.theseus', 'wb') as outfile:
  t.write_data(outfile)

The output is written in callgrind format, which means that standard tools can be used to interpret the results, such as kcachegrind.

If at any point the Tracer is no longer useful, it can be uninstalled to stop tracing:

t.uninstall()

Additionally, theseus is aware of inlineCallbacks, and will rewrite call stacks to make them look “correct”. For example, given this code:

from twisted.internet import defer, task

@defer.inlineCallbacks
def func(reactor):
  yield task.deferLater(reactor, 1, lambda: None)

task.react(func)

The call stack according to theseus will look like this (most recent call last):

__main__ in <module>
twisted.internet.task in react
__main__ in func

While theseus and cProfile both use a profile hook, as long as cProfile is installed first, both profilers can be used at the same time. In this case, calling uninstall() will restore cProfile.

Metadata

Release files for twisted-theseus 0.14.1.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 twisted-theseus 0.14.1.3
File Size Uploaded
twisted-theseus-0.14.1.3.tar.gz 28.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for twisted-theseus 0.14.1.3
File Interpreter ABI Platform
twisted_theseus-0.14.1.3-pp27-none-any.whl PyPy 2.7 none any Details

Total release size: 38.2 kB

Release files / twisted-theseus-0.14.1.3.tar.gz

Download URL twisted-theseus-0.14.1.3.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3b512afe228ebd60bc25a2a37c45bef97dd998306ccb8d4afb954b5c50f3ff74
BLAKE2b-256 checksum
How to use checksums
5322ae90b006419b6d7a0503d98fa3d0be5e3677a2e8906089b737de48d66f9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / twisted_theseus-0.14.1.3-pp27-none-any.whl

Download URL twisted_theseus-0.14.1.3-pp27-none-any.whl
Size 9.3 kB
Tags PyPy 2.7
SHA-256 checksum
How to use checksums
7edc3fb7e58d3707c51d786d8acb5b305b7bc3a11d3b00347608a30ee7b814a1
BLAKE2b-256 checksum
How to use checksums
268cef08bbf40321616c7ca39f240d7d9d2187d7582fc95ed51da466a46afe45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.14.1.3 This release

2 release files

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