File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change
1
+ import asyncio
1
2
import collections .abc
2
3
import threading
3
4
@@ -186,15 +187,25 @@ def copy_context():
186
187
187
188
188
189
def _get_context ():
189
- ctx = getattr (_state , 'context' , None )
190
+ state = _get_state ()
191
+ ctx = getattr (state , 'context' , None )
190
192
if ctx is None :
191
193
ctx = Context ()
192
- _state .context = ctx
194
+ state .context = ctx
193
195
return ctx
194
196
195
197
196
198
def _set_context (ctx ):
197
- _state .context = ctx
199
+ state = _get_state ()
200
+ state .context = ctx
201
+
202
+
203
+ def _get_state ():
204
+ loop = asyncio ._get_running_loop ()
205
+ if loop is None :
206
+ return _state
207
+ task = asyncio .Task .current_task (loop = loop )
208
+ return _state if task is None else task
198
209
199
210
200
211
_state = threading .local ()
You can’t perform that action at this time.
0 commit comments