Created
April 25, 2019 10:35
-
-
Save harunurkst/383d546a58cf0037f172267dc0d1681c to your computer and use it in GitHub Desktop.
asynchronous way to send dummy push. (Test function to get timing)
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
import time | |
import asyncio | |
import logging | |
async def send_push(user_id): | |
""" | |
demo function to send notification | |
""" | |
print("Start: "+str(user_id)) | |
await asyncio.sleep(1) # sleep 1 second when sending notification. | |
print("Complete: "+str(user_id)) | |
tasks = [] | |
if __name__=='__main__': | |
# starting time | |
t1 = time.time() | |
user_count = int(input("Enter total user: ")) | |
for user_id in range(user_count): | |
tasks.append(send_push(user_id)) | |
# event loop | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(asyncio.wait(tasks)) | |
# count total time | |
total_time = time.time() - t1 | |
print("Total time: " + str(total_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment