File: PKG-INFO

package info (click to toggle)
python-tblib 0.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 224 kB
  • ctags: 55
  • sloc: python: 224; makefile: 35
file content (267 lines) | stat: -rw-r--r-- 10,195 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
Metadata-Version: 1.1
Name: tblib
Version: 0.1.0
Summary: Traceback fiddling library.
Home-page: https://github.com/ionelmc/python-tblib
Author: Ionel Cristian Mărieș
Author-email: contact@ionelmc.ro
License: BSD
Description: ==========================
                python-tblib
        ==========================
        
        .. image:: https://secure.travis-ci.org/ionelmc/python-tblib.png?branch=master
            :alt: Build Status
            :target: http://travis-ci.org/ionelmc/python-tblib
        
        .. image:: https://coveralls.io/repos/ionelmc/python-tblib/badge.png?branch=master
            :alt: Coverage Status
            :target: https://coveralls.io/r/ionelmc/python-tblib
        
        .. image:: https://badge.fury.io/py/tblib.png
            :alt: PYPI Package
            :target: https://pypi.python.org/pypi/tblib
        
        Traceback fiddling library.
        
        Pickling tracebacks
        ===================
        
        **Note**: The traceback objects that come out are stripped of some attributes (like variables). But you'll be able to raise exceptions with
        those tracebacks or print them - that should cover 99% of the usecases.
        
        ::
        
            >>> from tblib import pickling_support
            >>> pickling_support.install()
            >>> import pickle, sys
            >>> def inner_0():
            ...     raise Exception('fail')
            ...
            >>> def inner_1():
            ...     inner_0()
            ...
            >>> def inner_2():
            ...     inner_1()
            ...
            >>> try:
            ...     inner_2()
            ... except:
            ...     s1 = pickle.dumps(sys.exc_info())
            ...
            >>> len(s1) > 1
            True
            >>> try:
            ...     inner_2()
            ... except:
            ...     s2 = pickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL)
            ...
            >>> len(s2) > 1
            True
        
            >>> try:
            ...     import cPickle
            ... except ImportError:
            ...     import pickle as cPickle
            >>> try:
            ...     inner_2()
            ... except:
            ...     s3 = cPickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL)
            ...
            >>> len(s3) > 1
            True
        
        Unpickling
        ----------
        
        ::
        
            >>> pickle.loads(s1)
            (<...Exception'>, Exception('fail',), <traceback object at ...>)
        
            >>> pickle.loads(s2)
            (<...Exception'>, Exception('fail',), <traceback object at ...>)
        
            >>> pickle.loads(s3)
            (<...Exception'>, Exception('fail',), <traceback object at ...>)
        
        Raising
        -------
        
        ::
        
            >>> from six import reraise
            >>> reraise(*pickle.loads(s1))
            Traceback (most recent call last):
              ...
              File "<doctest README.rst[14]>", line 1, in <module>
                reraise(*pickle.loads(s2))
              File "<doctest README.rst[8]>", line 2, in <module>
                inner_2()
              File "<doctest README.rst[5]>", line 2, in inner_2
                inner_1()
              File "<doctest README.rst[4]>", line 2, in inner_1
                inner_0()
              File "<doctest README.rst[3]>", line 2, in inner_0
                raise Exception('fail')
            Exception: fail
            >>> reraise(*pickle.loads(s2))
            Traceback (most recent call last):
              ...
              File "<doctest README.rst[14]>", line 1, in <module>
                reraise(*pickle.loads(s2))
              File "<doctest README.rst[8]>", line 2, in <module>
                inner_2()
              File "<doctest README.rst[5]>", line 2, in inner_2
                inner_1()
              File "<doctest README.rst[4]>", line 2, in inner_1
                inner_0()
              File "<doctest README.rst[3]>", line 2, in inner_0
                raise Exception('fail')
            Exception: fail
            >>> reraise(*pickle.loads(s3))
            Traceback (most recent call last):
              ...
              File "<doctest README.rst[14]>", line 1, in <module>
                reraise(*pickle.loads(s2))
              File "<doctest README.rst[8]>", line 2, in <module>
                inner_2()
              File "<doctest README.rst[5]>", line 2, in inner_2
                inner_1()
              File "<doctest README.rst[4]>", line 2, in inner_1
                inner_0()
              File "<doctest README.rst[3]>", line 2, in inner_0
                raise Exception('fail')
            Exception: fail
        
        The tblib.Traceback object
        ==========================
        
        It is used by the ``pickling_support``. You can use it too if you want more flexibility::
        
            >>> from tblib import Traceback
            >>> try:
            ...     inner_2()
            ... except:
            ...     et, ev, tb = sys.exc_info()
            ...     tb = Traceback(tb)
            ...     reraise(et, ev, tb.as_traceback())
            ...
            Traceback (most recent call last):
              ...
              File "<doctest README.rst[21]>", line 6, in <module>
                reraise(et, ev, tb.as_traceback())
              File "<doctest README.rst[21]>", line 2, in <module>
                inner_2()
              File "<doctest README.rst[5]>", line 2, in inner_2
                inner_1()
              File "<doctest README.rst[4]>", line 2, in inner_1
                inner_0()
              File "<doctest README.rst[3]>", line 2, in inner_0
                raise Exception('fail')
            Exception: fail
        
        Decorators
        ==========
        
        return_error
        ------------
        
        ::
        
            >>> from tblib.decorators import return_error
            >>> inner_2r = return_error(inner_2)
            >>> e = inner_2r()
            >>> e
            <tblib.decorators.Error object at ...>
            >>> e.reraise()
            Traceback (most recent call last):
              ...
              File "<doctest README.rst[26]>", line 1, in <module>
                e.reraise()
              File ".../tblib/decorators.py", line 19, in reraise
                reraise(self.exc_type, self.exc_value, self.traceback)
              File ".../tblib/decorators.py", line 25, in return_exceptions_wrapper
                return func(*args, **kwargs)
              File "<doctest README.rst[5]>", line 2, in inner_2
                inner_1()
              File "<doctest README.rst[4]>", line 2, in inner_1
                inner_0()
              File "<doctest README.rst[3]>", line 2, in inner_0
                raise Exception('fail')
            Exception: fail
        
        How's this useful ? Imagine you're using multiprocessing like this::
        
            >>> import traceback
            >>> from multiprocessing import Pool
            >>> from examples import func_a
            >>> pool = Pool()
            >>> try:
            ...     for i in pool.map(func_a, range(5)):
            ...         print(i)
            ... except:
            ...     print(traceback.format_exc())
            ...
            Traceback (most recent call last):
              File "<doctest README.rst[31]>", line 2, in <module>
                for i in pool.map(func_a, range(5)):
              File "/usr/lib/.../multiprocessing/pool.py", line ..., in map
                return self.map_async(func, iterable, chunksize).get()
              File "/usr/lib/.../multiprocessing/pool.py", line ..., in get
                raise self._value
            Exception: Guessing time !
            <BLANKLINE>
            >>> pool.terminate()
        
        Not very useful is it? Let's sort this out::
        
            >>> from tblib.decorators import apply_with_return_error, Error
            >>> from itertools import repeat
            >>> pool = Pool()
            >>> try:
            ...     for i in pool.map(apply_with_return_error, zip(repeat(func_a), range(5))):
            ...         if isinstance(i, Error):
            ...             i.reraise()
            ...         else:
            ...             print(i)
            ... except:
            ...     print(traceback.format_exc())
            ...
            Traceback (most recent call last):
              File "<doctest README.rst[36]>", line 4, in <module>
                i.reraise()
              File ".../tblib/decorators.py", line ..., in reraise
                reraise(self.exc_type, self.exc_value, self.traceback)
              File ".../tblib/decorators.py", line ..., in return_exceptions_wrapper
                return func(*args, **kwargs)
              File ".../tblib/decorators.py", line ..., in apply_with_return_error
                return args[0](*args[1:])
              File ".../examples.py", line 2, in func_a
                func_b()
              File ".../examples.py", line 5, in func_b
                func_c()
              File ".../examples.py", line 8, in func_c
                func_d()
              File ".../examples.py", line 11, in func_d
                raise Exception("Guessing time !")
            Exception: Guessing time !
            <BLANKLINE>
            >>> pool.terminate()
        
        Much better !
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Debuggers
Classifier: Topic :: Utilities
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy