<jupyter_start><jupyter_text>Code to generate random numbers in a file<jupyter_code># import random

# with open('random_nums.txt', 'w') as fout:
#     for _ in range(10):
#         rand_num = str(random.randint(1, 100))
#         fout.write(rand_num)
#         fout.write('\n')<jupyter_output><empty_output><jupyter_text>Asynchronous Calls<jupyter_code>import asyncio
async def process_users(file_name):
    now = datetime.datetime.now()
    cur_year =  now.year
    with open(file_name) as f_out:
        csvreader = csv.reader(f_out)
        for line in csvreader:
            name, year, sex = list(map(get_info, line))
            if sex == 'Male':
                name = 'Mr.' + name
            else:
                name = 'Ms/Mrs. ' + name
            age = cur_year - int(year)
            
            print("Age of {} is {} years".format(name, age))
            await asyncio.sleep(1)
    print("Done Processing User Info !")
async def process_numbers(file_name):
    with open(file_name) as fnums:
        for num in fnums:
            num = int(num.strip())
            if num%15==0:
                print("For {} the ans is {}".format(num, 'FizzBuzz'))
                await asyncio.sleep(3)
            elif num%3==0:
                print("For {} the ans is {}".format(num, 'Fizz'))
                await asyncio.sleep(2)
            elif num%5==0:
                print("For {} the ans is {}".format(num, 'Buzz'))
                await asyncio.sleep(1)
            else:
                print("For {} the ans is {} itself".format(num, num))
            
    print("Finished Processing Numbers")
async def process_string(my_str):
    for char in my_str:
        if char.isdigit():
            print("{} is a digit".format(char))
            await asyncio.sleep(2)
        elif char.isalpha():
            if char in 'aeiou':
                print("{} is a vowel".format(char))
            else:
                print("{} is an alphabet".format(char))
            await asyncio.sleep(1)
        elif char.isspace():
            continue
        else:
            print("{} is a special character".format(char))
        
    
async def async_call_new():
  user_obj = event_loop.create_task(process_users('user_info.csv'))
  nums_obj = event_loop.create_task(process_numbers("random_nums.txt"))
  str_obj = event_loop.create_task(process_string("Hello World !"))
  await asyncio.wait([user_obj, nums_obj, str_obj])
# event_loop = asyncio.get_event_loop()
# event_loop.run_until_complete(async_call_new())
# event_loop.close()
async def async_call_run():
  user_obj = asyncio.create_task(process_users('user_info.csv'))
  nums_obj = asyncio.create_task(process_numbers("random_nums.txt"))
  str_obj = asyncio.create_task(process_string("Hello World !"))
  await asyncio.wait([user_obj, nums_obj, str_obj])
# https://docs.python.org/3/library/asyncio-task.html#asyncio.run

asyncio.run(async_call_run())<jupyter_output>Age of Mr.<NAME> is 35 years
For 24 the ans is Fizz
H is an alphabet
Age of Ms/Mrs. <NAME> is 50 years
e is a vowel
For 42 the ans is Fizz
Age of Mr.Jimmy is 45 years
l is an alphabet
Age of Ms/Mrs. <NAME> is 30 years
l is an alphabet
For 43 the ans is 43 itself
For 5 the ans is Buzz
Age of Ms/Mrs. <NAME> is 32 years
o is a vowel
For 88 the ans is 88 itself
For 44 the ans is 44 itself
For 67 the ans is 67 itself
For 42 the ans is Fizz
Done Processing User Info !
W is an alphabet
o is a vowel
For 54 the ans is Fizz
r is an alphabet
l is an alphabet
For 88 the ans is 88 itself
Finished Processing Numbers
d is an alphabet
! is a special character
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.016471245114461196, 'mean_word_length': 2.5161923454367026, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '591566', 'license': 'MIT', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1148, 'n_words': 347, 'path': 'Section_8/AsyncIO Python.ipynb', 'repo_name': 'PacktPublishing/Software-Engineering-with-Python-3.x', 'size': '3601'}