Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 2945cb2

Browse files
committed
Fix aux_func/loop init
1 parent 928adfa commit 2945cb2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

samples/django/13.core-bot/bots/bots.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
""" Bot initialization """
55
# pylint: disable=line-too-long
66
import sys
7+
import asyncio
78
from django.apps import AppConfig
89
from botbuilder.core import (BotFrameworkAdapter, BotFrameworkAdapterSettings, TurnContext, ConversationState, MemoryStorage, UserState)
910
from dialogs import MainDialog
@@ -17,6 +18,7 @@ class BotConfig(AppConfig):
1718

1819
SETTINGS = BotFrameworkAdapterSettings(appConfig.APP_ID, appConfig.APP_PASSWORD)
1920
ADAPTER = BotFrameworkAdapter(SETTINGS)
21+
LOOP = asyncio.get_event_loop()
2022

2123
# Create MemoryStorage, UserState and ConversationState
2224
memory = MemoryStorage()

samples/django/13.core-bot/bots/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ def messages(request):
3030

3131
activity = Activity().deserialize(body)
3232
auth_header = request.headers['Authorization'] if 'Authorization' in request.headers else ''
33-
loop = asyncio.get_event_loop()
3433

3534
bot_app = apps.get_app_config('bots')
3635
bot = bot_app.bot
3736
adapter = bot_app.ADAPTER
3837

3938
async def aux_func(turn_context):
40-
asyncio.ensure_future(bot.on_turn(turn_context), loop=loop)
39+
await bot.on_turn(turn_context)
40+
4141
try:
42-
task = asyncio.ensure_future(adapter.process_activity(activity, auth_header, aux_func), loop=loop)
43-
loop.run_until_complete(task)
42+
task = asyncio.ensure_future(adapter.process_activity(activity, auth_header, aux_func), loop=bot_app.LOOP)
43+
bot_app.LOOP.run_until_complete(task)
4444
return HttpResponse(status=201)
4545
except Exception as exception:
4646
raise exception

0 commit comments

Comments
 (0)