我正在尝试为下面的代码实现多处理,但似乎什么都不起作用。模式和输出是包含数十万个元素的列表。
for pat in patterns:
for seq in [output[x] for x in range(0, len(output)) if x % 2 != 0]:
freq = freq + get_count(seq, pat)
freq_dict[pat] = freq
freq = 0
任何形式的帮助都将不胜感激。
试试这个:
import concurrent
def add_pattern(pat):
for seq in [output[x] for x in range(0, len(output)) if x % 2 != 0]:
freq = freq + get_count(seq, pat)
freq_dict[pat] = freq
freq = 0
with concurrent.futures.ProcessPoolExecutor() as executor:
executor.map(add_pattern, patterns)