Skip to main content

OpenCensus Runtime Context

Project description

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

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

opencensus-context-0.2.dev0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencensus_context-0.2.dev0-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file opencensus-context-0.2.dev0.tar.gz.

File metadata

  • Download URL: opencensus-context-0.2.dev0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for opencensus-context-0.2.dev0.tar.gz
Algorithm Hash digest
SHA256 10ab2bc631a72257018e49e3e4b81e6c117c0cfb2f28d4b52b3c7da722d3042c
MD5 73ba3cb41ac0504201abe4c97d373214
BLAKE2b-256 f53e676c048bc92b27937d497e82374d3bbd6fe5c9df5a6d2d97674103c6ef36

See more details on using hashes here.

File details

Details for the file opencensus_context-0.2.dev0-py2.py3-none-any.whl.

File metadata

  • Download URL: opencensus_context-0.2.dev0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for opencensus_context-0.2.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 01d09c98c1be6f99364bc8571f74665bae216538f2e9f85084740e1649c867b0
MD5 ec716b9c45644747d248a58bd843ea59
BLAKE2b-256 7dd892ec4bd2c362618035f4011e2cd37dcea69c0e90c751d88263e7fa3804d7

See more details on using hashes here.

Supported by

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