File: greenthread.py

package info (click to toggle)
python-eventlet 0.26.1-7%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,916 kB
  • sloc: python: 24,898; makefile: 98
file content (33 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from eventlet import greenthread

from eventlet.zipkin import api


__original_init__ = greenthread.GreenThread.__init__
__original_main__ = greenthread.GreenThread.main


def _patched__init(self, parent):
    # parent thread saves current TraceData from tls to self
    if api.is_tracing():
        self.trace_data = api.get_trace_data()

    __original_init__(self, parent)


def _patched_main(self, function, args, kwargs):
    # child thread inherits TraceData
    if hasattr(self, 'trace_data'):
        api.set_trace_data(self.trace_data)

    __original_main__(self, function, args, kwargs)


def patch():
    greenthread.GreenThread.__init__ = _patched__init
    greenthread.GreenThread.main = _patched_main


def unpatch():
    greenthread.GreenThread.__init__ = __original_init__
    greenthread.GreenThread.main = __original_main__