Skip to content

Commit 5350c19

Browse files
committed
fix: better cache handeling by waiting for the result
1 parent e8956ef commit 5350c19

5 files changed

Lines changed: 51 additions & 4 deletions

File tree

beet/core/cache.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,19 @@ def download(self, arg: Union[str, Request], path: FileSystemPath) -> Path:
380380

381381
if not path.is_file():
382382
fileobj = path.open("wb")
383-
if self.executor:
384-
self.executor.submit(self.retrieve, arg, fileobj)
385-
else:
386-
self.retrieve(arg, fileobj)
383+
try:
384+
if self.executor:
385+
future = self.executor.submit(self.retrieve, arg, fileobj)
386+
future.result()
387+
else:
388+
self.retrieve(arg, fileobj)
389+
except Exception as e:
390+
try:
391+
fileobj.close()
392+
path.unlink()
393+
except Exception:
394+
pass
395+
raise e
387396

388397
return path
389398

examples/cache_test/beet.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
meta:
2+
vanilla:
3+
version: "1.21.8"
4+
5+
pipeline:
6+
- mre

examples/cache_test/mre.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from beet import Context
2+
from beet.contrib.vanilla import Vanilla
3+
4+
5+
def beet_default(ctx: Context):
6+
ctx.inject(Vanilla).mount("assets/minecraft/font", fetch_objects=True)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"pack": {
3+
"min_format": [
4+
88,
5+
0
6+
],
7+
"max_format": [
8+
88,
9+
0
10+
],
11+
"description": ""
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"pack": {
3+
"min_format": [
4+
69,
5+
0
6+
],
7+
"max_format": [
8+
69,
9+
0
10+
],
11+
"description": ""
12+
}
13+
}

0 commit comments

Comments
 (0)