python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio
Other
187 stars 37 forks source link

Cancel and join asyncio tasks when exiting an open_loop() block #108

Closed oremanj closed 3 years ago

oremanj commented 3 years ago

This makes open_loop() work like asyncio.run(), giving "background" tasks a chance to unwind themselves, rather than simply abandoning them to the garbage collector.

Like asyncio.run(), we don't catch tasks that are spawned after delivering the cancellations -- those will get abandoned like before. This is maybe fixable in theory but it's probably more trouble than it's worth.

Fixes #91

codecov[bot] commented 3 years ago

Codecov Report

Merging #108 (50617c8) into master (dd4476b) will increase coverage by 0.59%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
+ Coverage   81.64%   82.23%   +0.59%     
==========================================
  Files          11       11              
  Lines        1193     1199       +6     
  Branches      172      175       +3     
==========================================
+ Hits          974      986      +12     
+ Misses        155      151       -4     
+ Partials       64       62       -2     
Impacted Files Coverage Δ
trio_asyncio/_loop.py 79.90% <100.00%> (+0.57%) :arrow_up:
trio_asyncio/_base.py 84.14% <0.00%> (+0.57%) :arrow_up:
trio_asyncio/_util.py 88.63% <0.00%> (+4.54%) :arrow_up: