Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

async sync Synchronous Asynchronous

Synchronous Execution

My boss is a busy man. He tells me to write code. I tell him: Fine. I get started and he's watching me like a vulture, standing behind me, off my shoulder. I'm like "Dude, WTF: why don't you go and do something while I finish this?"

he's like: "No, I'm waiting right here until you finish." This is synchronous.

Asynchronous Execution

The boss tells me to do it, and rather than waiting right there for my work, the boss goes off and does other tasks. When I finish my job I simply report to my boss and say: "I'm DONE!" This is Asynchronous Execution.

(Take my advice: NEVER work with the boss behind you.)

Comment

Async-Sync

def get_chat_id(name):
    time.sleep(3)
    return "chat-%s" % name

async def main():
    result = get_chat_id("django")
Comment

Async-Sync

async def get_chat_id(name):
    await asyncio.sleep(3)
    return "chat-%s" % name

async def main():
    id_coroutine = get_chat_id("django")
    result = await id_coroutine
Comment

PREVIOUS NEXT
Code Example
Python :: num2words python 
Python :: python foreach 2d array 
Python :: lambda expression python 
Python :: double underscore methods python 
Python :: python call function that need args with decorator 
Python :: why is c++ faster than python 
Python :: Counter() Function 
Python :: sample hyperparameter tuning with grid search cv 
Python :: discord bot python get message id 
Python :: time a function python 
Python :: import sentence transformers 
Python :: what is django python 
Python :: copy python 
Python :: python list comprehensions 
Python :: greater and less than in python 
Python :: datetime conversion 
Python :: onehot encode list of columns pandas 
Python :: insert in python 
Python :: how to index lists in python 
Python :: replace nan from another column 
Python :: os.path.join 
Python :: How to split a string into a dictionary in Python 
Python :: how to use djoser signals 
Python :: sparse matrix multiplication in python 
Python :: pyhon sort a list of tuples 
Python :: python get the last in dictionary 
Python :: remove item in dict 
Python :: how to load a keras model with custom loss function 
Python :: if queryset is empty django 
Python :: string length python 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =