Returns this thread's context. If this thread does not yet have a context, returns a new context and sets this thread's context. New contexts are copies of DefaultContext.
()
| 351 | ) |
| 352 | |
| 353 | def getcontext(): |
| 354 | """Returns this thread's context. |
| 355 | |
| 356 | If this thread does not yet have a context, returns |
| 357 | a new context and sets this thread's context. |
| 358 | New contexts are copies of DefaultContext. |
| 359 | """ |
| 360 | try: |
| 361 | return _current_context_var.get() |
| 362 | except LookupError: |
| 363 | context = Context() |
| 364 | _current_context_var.set(context) |
| 365 | return context |
| 366 | |
| 367 | def setcontext(context): |
| 368 | """Set this thread's context to context.""" |