Skip to content

Commit d92b520

Browse files
authored
Merge pull request python#101 from mgmacias95/pythonGH-91048-tasks
2 parents c3a6bcb + 5e1cb87 commit d92b520

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

Lib/asyncio/tools.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ def build_task_table(result):
144144
table = []
145145
for tid, tasks in result:
146146
for task_id, task_name, awaited in tasks:
147+
if not awaited:
148+
table.append(
149+
[
150+
tid,
151+
hex(task_id),
152+
task_name,
153+
"",
154+
"",
155+
"0x0"
156+
]
157+
)
147158
for stack, awaiter_id in awaited:
148159
coroutine_chain = " -> ".join(stack)
149160
awaiter_name = id2name.get(awaiter_id, "Unknown")

Lib/test/test_asyncio/test_tools.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,37 @@
164164
]
165165
),
166166
],
167+
[
168+
# test case containing two roots, one of them without subtasks
169+
(
170+
[
171+
(1, [(2, "Task-5", [])]),
172+
(
173+
3,
174+
[
175+
(4, "Task-1", []),
176+
(5, "Task-2", [[["main"], 4]]),
177+
(6, "Task-3", [[["main"], 4]]),
178+
(7, "Task-4", [[["main"], 4]]),
179+
],
180+
),
181+
(8, []),
182+
(0, []),
183+
]
184+
),
185+
(
186+
[
187+
["└── (T) Task-5"],
188+
[
189+
"└── (T) Task-1",
190+
" └── main",
191+
" ├── (T) Task-2",
192+
" ├── (T) Task-3",
193+
" └── (T) Task-4",
194+
],
195+
]
196+
),
197+
],
167198
]
168199

169200
TEST_INPUTS_CYCLES_TREE = [
@@ -300,6 +331,7 @@
300331
),
301332
(
302333
[
334+
[1, "0x2", "Task-1", "", "", "0x0"],
303335
[
304336
1,
305337
"0x3",
@@ -409,15 +441,45 @@
409441
),
410442
(
411443
[
444+
[9, "0x5", "Task-5", "", "", "0x0"],
412445
[9, "0x6", "Task-6", "main2", "Task-5", "0x5"],
413446
[9, "0x7", "Task-7", "main2", "Task-5", "0x5"],
414447
[9, "0x8", "Task-8", "main2", "Task-5", "0x5"],
448+
[10, "0x1", "Task-1", "", "", "0x0"],
415449
[10, "0x2", "Task-2", "main", "Task-1", "0x1"],
416450
[10, "0x3", "Task-3", "main", "Task-1", "0x1"],
417451
[10, "0x4", "Task-4", "main", "Task-1", "0x1"],
418452
]
419453
),
420454
],
455+
[
456+
# test case containing two roots, one of them without subtasks
457+
(
458+
[
459+
(1, [(2, "Task-5", [])]),
460+
(
461+
3,
462+
[
463+
(4, "Task-1", []),
464+
(5, "Task-2", [[["main"], 4]]),
465+
(6, "Task-3", [[["main"], 4]]),
466+
(7, "Task-4", [[["main"], 4]]),
467+
],
468+
),
469+
(8, []),
470+
(0, []),
471+
]
472+
),
473+
(
474+
[
475+
[1, "0x2", "Task-5", "", "", "0x0"],
476+
[3, "0x4", "Task-1", "", "", "0x0"],
477+
[3, "0x5", "Task-2", "main", "Task-1", "0x4"],
478+
[3, "0x6", "Task-3", "main", "Task-1", "0x4"],
479+
[3, "0x7", "Task-4", "main", "Task-1", "0x4"],
480+
]
481+
),
482+
],
421483
# CASES WITH CYCLES
422484
[
423485
# this test case contains a cycle: two tasks awaiting each other.
@@ -440,6 +502,7 @@
440502
),
441503
(
442504
[
505+
[1, "0x2", "Task-1", "", "", "0x0"],
443506
[1, "0x3", "a", "awaiter2", "b", "0x4"],
444507
[1, "0x3", "a", "main", "Task-1", "0x2"],
445508
[1, "0x4", "b", "awaiter", "a", "0x3"],
@@ -480,6 +543,7 @@
480543
),
481544
(
482545
[
546+
[1, "0x2", "Task-1", "", "", "0x0"],
483547
[
484548
1,
485549
"0x3",
@@ -570,7 +634,10 @@ def test_only_independent_tasks_tree(self):
570634

571635
def test_only_independent_tasks_table(self):
572636
input_ = [(1, [(10, "taskA", []), (11, "taskB", [])])]
573-
self.assertEqual(tools.build_task_table(input_), [])
637+
self.assertEqual(
638+
tools.build_task_table(input_),
639+
[[1, "0xa", "taskA", "", "", "0x0"], [1, "0xb", "taskB", "", "", "0x0"]],
640+
)
574641

575642
def test_single_task_tree(self):
576643
"""Test print_async_tree with a single task and no awaits."""
@@ -599,7 +666,7 @@ def test_single_task_table(self):
599666
],
600667
)
601668
]
602-
expected_output = []
669+
expected_output = [[1, "0x2", "Task-1", "", "", "0x0"]]
603670
self.assertEqual(tools.build_task_table(result), expected_output)
604671

605672
def test_cycle_detection(self):
@@ -653,6 +720,7 @@ def test_complex_table(self):
653720
)
654721
]
655722
expected_output = [
723+
[1, "0x2", "Task-1", "", "", "0x0"],
656724
[1, "0x3", "Task-2", "main", "Task-1", "0x2"],
657725
[1, "0x4", "Task-3", "main", "Task-2", "0x3"],
658726
]

0 commit comments

Comments
 (0)