Skip to main content

OpenCensus Runtime Context

pypi

The OpenCensus Runtime Context provides in-process context propagation. By default, thread local storage is used for Python 2.7, 3.4 and 3.5; contextvars is used for Python >= 3.6, which provides asyncio support.

Installation

This library is installed by default with opencensus, there is no need to install it explicitly.

Usage

In most cases context propagation happens automatically within a process, following the control flow of threads and asynchronous coroutines. The runtime context is a dictionary stored in a context variable when available, and in thread local storage otherwise.

There are cases where you may want to propagate the context explicitly:

Explicit Thread Creation

from threading import Thread
from opencensus.common.runtime_context import RuntimeContext

def work(name):
    # here you will get the context from the parent thread
    print(RuntimeContext)

thread = Thread(
    # propagate context explicitly
    target=RuntimeContext.with_current_context(work),
    args=('foobar',),
)
thread.start()
thread.join()

Thread Pool

from multiprocessing.dummy import Pool as ThreadPool
from opencensus.common.runtime_context import RuntimeContext

def work(name):
    # here you will get the context from the parent thread
    print(RuntimeContext)

pool = ThreadPool(2)
# propagate context explicitly
pool.map(RuntimeContext.with_current_context(work), [
    'bear',
    'cat',
    'dog',
    'horse',
    'rabbit',
])
pool.close()
pool.join()

References

Metadata

Release files for opencensus-context 0.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 opencensus-context 0.1.3
File Size Uploaded
opencensus-context-0.1.3.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opencensus-context 0.1.3
File Interpreter ABI Platform
opencensus_context-0.1.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.1 kB

Release files / opencensus-context-0.1.3.tar.gz

Download URL opencensus-context-0.1.3.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a03108c3c10d8c80bb5ddf5c8a1f033161fa61972a9917f9b9b3a18517f0088c
BLAKE2b-256 checksum
How to use checksums
4c963b6f638f6275a8abbd45e582448723bffa29c1fb426721dedb5c72f7d056
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9

Release files / opencensus_context-0.1.3-py2.py3-none-any.whl

Download URL opencensus_context-0.1.3-py2.py3-none-any.whl
Size 5.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
073bb0590007af276853009fac7e4bab1d523c3f03baf4cb4511ca38967c6039
BLAKE2b-256 checksum
How to use checksums
1068162c97ea78c957d68ecf78a5c5041d2e25bd5562bdf5d89a6cbf7f8429bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

1 release file

0.1.0

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