feat: add retry execption
Browse files- font_dataset/text.py +5 -0
font_dataset/text.py
CHANGED
@@ -31,10 +31,15 @@ def random_char(length: int, font: DSFont, char_set: str) -> str:
|
|
31 |
assert len(char_set) > 0
|
32 |
|
33 |
ret = ""
|
|
|
34 |
while len(ret) < length:
|
35 |
char = char_set[random.randint(0, len(char_set) - 1)]
|
36 |
if char_in_font(char, font.path):
|
37 |
ret += char
|
|
|
|
|
|
|
|
|
38 |
|
39 |
return ret
|
40 |
|
|
|
31 |
assert len(char_set) > 0
|
32 |
|
33 |
ret = ""
|
34 |
+
fail_cnt = 0
|
35 |
while len(ret) < length:
|
36 |
char = char_set[random.randint(0, len(char_set) - 1)]
|
37 |
if char_in_font(char, font.path):
|
38 |
ret += char
|
39 |
+
else:
|
40 |
+
fail_cnt += 1
|
41 |
+
if fail_cnt > 1000:
|
42 |
+
raise Exception(f"Too many fail for font: {font.path}")
|
43 |
|
44 |
return ret
|
45 |
|