@@ -568,9 +568,8 @@ async def start(self) -> None:
568568 try :
569569 if self .persistence :
570570 self .__update_persistence_task = asyncio .create_task (
571- self ._persistence_updater ()
572- # TODO: Add this once we drop py3.7
573- # name=f'Application:{self.bot.id}:persistence_updater'
571+ self ._persistence_updater (),
572+ name = f"Application:{ self .bot .id } :persistence_updater" ,
574573 )
575574 _LOGGER .debug ("Loop for updating persistence started" )
576575
@@ -579,9 +578,7 @@ async def start(self) -> None:
579578 _LOGGER .debug ("JobQueue started" )
580579
581580 self .__update_fetcher_task = asyncio .create_task (
582- self ._update_fetcher (),
583- # TODO: Add this once we drop py3.7
584- # name=f'Application:{self.bot.id}:update_fetcher'
581+ self ._update_fetcher (), name = f"Application:{ self .bot .id } :update_fetcher"
585582 )
586583 _LOGGER .info ("Application started" )
587584
@@ -955,6 +952,8 @@ def create_task(
955952 self ,
956953 coroutine : Union [Generator [Optional ["asyncio.Future[object]" ], None , RT ], Awaitable [RT ]],
957954 update : Optional [object ] = None ,
955+ * ,
956+ name : Optional [str ] = None ,
958957 ) -> "asyncio.Task[RT]" :
959958 """Thin wrapper around :func:`asyncio.create_task` that handles exceptions raised by
960959 the :paramref:`coroutine` with :meth:`process_error`.
@@ -977,16 +976,22 @@ def create_task(
977976 :attr:`chat_data` and :attr:`user_data` entries will be updated in the next run of
978977 :meth:`update_persistence` after the :paramref:`coroutine` is finished.
979978
979+ Keyword Args:
980+ name (:obj:`str`, optional): The name of the task.
981+
982+ .. versionadded:: NEXT.VERSION
983+
980984 Returns:
981985 :class:`asyncio.Task`: The created task.
982986 """
983- return self .__create_task (coroutine = coroutine , update = update )
987+ return self .__create_task (coroutine = coroutine , update = update , name = name )
984988
985989 def __create_task (
986990 self ,
987991 coroutine : Union [Generator [Optional ["asyncio.Future[object]" ], None , RT ], Awaitable [RT ]],
988992 update : Optional [object ] = None ,
989993 is_error_handler : bool = False ,
994+ name : Optional [str ] = None ,
990995 ) -> "asyncio.Task[RT]" :
991996 # Unfortunately, we can't know if `coroutine` runs one of the error handler functions
992997 # but by passing `is_error_handler=True` from `process_error`, we can make sure that we
@@ -995,7 +1000,8 @@ def __create_task(
9951000 task : "asyncio.Task[RT]" = asyncio .create_task (
9961001 self .__create_task_callback (
9971002 coroutine = coroutine , update = update , is_error_handler = is_error_handler
998- )
1003+ ),
1004+ name = name ,
9991005 )
10001006
10011007 if self .running :
@@ -1076,6 +1082,7 @@ async def _update_fetcher(self) -> None:
10761082 self .create_task (
10771083 self .__process_update_wrapper (update ),
10781084 update = update ,
1085+ name = f"Application:{ self .bot .id } :process_concurrent_update" ,
10791086 )
10801087 else :
10811088 await self .__process_update_wrapper (update )
@@ -1132,7 +1139,12 @@ async def process_update(self, update: object) -> None:
11321139 and self .bot .defaults
11331140 and not self .bot .defaults .block
11341141 ):
1135- self .create_task (coroutine , update = update )
1142+ self .create_task (
1143+ coroutine ,
1144+ update = update ,
1145+ name = f"Application:{ self .bot .id } :process_update_non_blocking"
1146+ f":{ handler } " ,
1147+ )
11361148 else :
11371149 any_blocking = True
11381150 await coroutine
@@ -1203,7 +1215,10 @@ def add_handler(self, handler: BaseHandler[Any, CCT], group: int = DEFAULT_GROUP
12031215 f"can not be persistent if application has no persistence"
12041216 )
12051217 if self ._initialized :
1206- self .create_task (self ._add_ch_to_persistence (handler ))
1218+ self .create_task (
1219+ self ._add_ch_to_persistence (handler ),
1220+ name = f"Application:{ self .bot .id } :add_handler:conversation_handler_after_init" ,
1221+ )
12071222 warn (
12081223 "A persistent `ConversationHandler` was passed to `add_handler`, "
12091224 "after `Application.initialize` was called. This is discouraged."
@@ -1683,7 +1698,10 @@ async def process_error(
16831698 and not self .bot .defaults .block
16841699 ):
16851700 self .__create_task (
1686- callback (update , context ), update = update , is_error_handler = True
1701+ callback (update , context ),
1702+ update = update ,
1703+ is_error_handler = True ,
1704+ name = f"Application:{ self .bot .id } :process_error:non_blocking" ,
16871705 )
16881706 else :
16891707 try :
0 commit comments