Created
January 24, 2019 16:38
-
-
Save Saren-Arterius/ba8242aac552989acf9646597825e795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from multiprocessing import Pool | |
from random import randint | |
longstr = str(2 ** 1000000) * 1000 # 280mb string | |
searches = [str(randint(10 ** 8, 10 ** 9)) for i in range(10000)] | |
def search_fn(s): | |
return s, s in longstr | |
def is_lucky(): | |
with Pool() as p: | |
for i, result in enumerate(p.imap_unordered(search_fn, searches)): | |
s, contains = result | |
print(f'[{i}] Search {s}') | |
if contains: | |
print(f'Found {s}') | |
return True | |
return False | |
if __name__ == "__main__": | |
print('Lucky', is_lucky()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment