| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -458,25 +458,18 @@ def create_future(self): | |||
| 458 | 458 | """Create a Future object attached to the loop.""" | |
| 459 | 459 | return futures.Future(loop=self) | |
| 460 | 460 | ||
| 461 | - def create_task(self, coro, *, name=None, context=None): | ||
| 461 | + def create_task(self, coro, *, **kwargs): | ||
| 462 | 462 | """Schedule a coroutine object. | |
| 463 | 463 | ||
| 464 | 464 | Return a task object. | |
| 465 | 465 | """ | |
| 466 | 466 | self._check_closed() | |
| 467 | 467 | if self._task_factory is None: | |
| 468 | - task = tasks.Task(coro, loop=self, name=name, context=context) | ||
| 468 | + task = tasks.Task(coro, loop=self, **kwargs) | ||
| 469 | 469 | if task._source_traceback: | |
| 470 | 470 | del task._source_traceback[-1] | |
| 471 | 471 | else: | |
| 472 | - if context is None: | ||
| 473 | - # Use legacy API if context is not needed | ||
| 474 | - task = self._task_factory(self, coro) | ||
| 475 | - else: | ||
| 476 | - task = self._task_factory(self, coro, context=context) | ||
| 477 | - | ||
| 478 | - task.set_name(name) | ||
| 479 | - | ||
| 472 | + task = self._task_factory(self, coro, **kwargs) | ||
| 480 | 473 | try: | |
| 481 | 474 | return task | |
| 482 | 475 | finally: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ async def _aexit(self, et, exc): | |||
| 178 | 178 | exc = None | |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | - def create_task(self, coro, *, name=None, context=None): | ||
| 181 | + def create_task(self, coro, *, **kwargs): | ||
| 182 | 182 | """Create a new task in this group and return it. | |
| 183 | 183 | ||
| 184 | 184 | Similar to `asyncio.create_task`. | |
@@ -192,10 +192,8 @@ def create_task(self, coro, *, name=None, context=None): | |||
| 192 | 192 | if self._aborting: | |
| 193 | 193 | coro.close() | |
| 194 | 194 | raise RuntimeError(f"TaskGroup {self!r} is shutting down") | |
| 195 | - if context is None: | ||
| 196 | - task = self._loop.create_task(coro, name=name) | ||
| 197 | - else: | ||
| 198 | - task = self._loop.create_task(coro, name=name, context=context) | ||
| 195 | + | ||
| 196 | + task = self._loop.create_task(coro, **kwargs) | ||
| 199 | 197 | ||
| 200 | 198 | # optimization: Immediately call the done callback if the task is | |
| 201 | 199 | # already done (e.g. if the coro was able to complete eagerly), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -384,19 +384,12 @@ def __wakeup(self, future): | |||
| 384 | 384 | Task = _CTask = _asyncio.Task | |
| 385 | 385 | ||
| 386 | 386 | ||
| 387 | - def create_task(coro, *, name=None, context=None): | ||
| 387 | + def create_task(coro, *, **kwargs): | ||
| 388 | 388 | """Schedule the execution of a coroutine object in a spawn task. | |
| 389 | 389 | ||
| 390 | 390 | Return a Task object. | |
| 391 | 391 | """ | |
| 392 | - loop = events.get_running_loop() | ||
| 393 | - if context is None: | ||
| 394 | - # Use legacy API if context is not needed | ||
| 395 | - task = loop.create_task(coro, name=name) | ||
| 396 | - else: | ||
| 397 | - task = loop.create_task(coro, name=name, context=context) | ||
| 398 | - | ||
| 399 | - return task | ||
| 392 | + return events.get_running_loop().create_task(coro, **kwargs) | ||
| 400 | 393 | ||
| 401 | 394 | ||
| 402 | 395 | # wait() and as_completed() similar to those in PEP 3148. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments