@@ -155,11 +155,11 @@ async def dispatch_forever(self): # sourcery skip: swap-if-expression
155
155
worker_id = self .worker_id )))
156
156
157
157
# In Python 3.11+, constructing a task has an optional context
158
- # parameter
158
+ # parameter. Allow for this param to be passed to ContextEnabledTask
159
159
# https://github.com/Azure/azure-functions-python-worker/issues/1508
160
160
self ._loop .set_task_factory (
161
- lambda loop , coro , context = None : ContextEnabledTask (
162
- coro , loop = loop , context = context ))
161
+ lambda loop , coro , context = None : ContextEnabledTask (
162
+ coro , loop = loop , context = context ))
163
163
164
164
# Detach console logging before enabling GRPC channel logging
165
165
logger .info ('Detaching console logging.' )
@@ -1017,6 +1017,8 @@ class ContextEnabledTask(asyncio.Task):
1017
1017
AZURE_INVOCATION_ID = '__azure_function_invocation_id__'
1018
1018
1019
1019
def __init__ (self , coro , loop , context = None ):
1020
+ # The context param is only available for 3.11+. If
1021
+ # not, it can't be sent in the init() call.
1020
1022
if sys .version_info .minor >= 11 :
1021
1023
super ().__init__ (coro , loop = loop , context = context )
1022
1024
else :
0 commit comments