Skip to content

Commit

Permalink
feat: add pool processes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzcn committed May 11, 2021
1 parent 02db55a commit 051a403
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tools/baiduspider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from multiprocessing import Pool, cpu_count
from pypinyin import pinyin, Style
import tqdm
import math

host = "https://shurufa.baidu.com"
archives_url = host + "/dict"
Expand Down Expand Up @@ -81,7 +82,7 @@ def processTag(tag):

def download_dicts():
total = len(dicts)
with Pool(processes=cpu_count() - 1) as pool:
with Pool(processes=max(cpu_count() - 1, 8)) as pool:
r = list(tqdm.tqdm(pool.imap_unordered(download_dict, dicts), total=total))

def download_dict(dict):
Expand Down
2 changes: 1 addition & 1 deletion tools/rime_dict_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def processDict(dictFile, finalDicts):
finalDicts = manager.WordDict()

processor = functools.partial(processDict, finalDicts=finalDicts)
with Pool(processes=cpu_count() - 1) as pool:
with Pool(processes=max(cpu_count() - 1, 8)) as pool:
r = list(tqdm.tqdm(pool.imap_unordered(processor, files), total=total))
if output:
filename = os.path.splitext(os.path.basename(output))[0].split('.dict')[0]
Expand Down

0 comments on commit 051a403

Please sign in to comment.