- Which module is used for asynchronous programming in Python?
View Answer
Correct answer: A — asyncio
- What will be printed?
1 python 2 import asyncio 3 print(hasattr(asyncio,"run")) View Answer
Correct answer: A — True
- Which keyword is used to define an asynchronous function?
View Answer
Correct answer: A — async
- What is the output of below code?
1 python 2 import asyncio 3 async def show(): 4 return "Eduinq" 5 print(asyncio.run(show())) View Answer
Correct answer: A — Eduinq
- Which keyword is used to wait for coroutine result?
View Answer
Correct answer: A — await
- What will be printed?
1 python 2 import asyncio 3 async def show(): 4 await asyncio.sleep(1) 5 return "Eduinq" 6 print(asyncio.run(show())) View Answer
Correct answer: A — Eduinq
- Which of the following is used to gather multiple coroutines?
View Answer
Correct answer: A — asyncio.gather()
- What is the output of below code?
1 python 2 import asyncio 3 async def one(): return "E" 4 async def two(): return "duinq" 5 print(asyncio.run(asyncio.gather(one(),two()))) View Answer
Correct answer: A — ['E','duinq']
- Which of the following is used to create tasks?
View Answer
Correct answer: A — asyncio.create_task()
- What will be printed?
1 python 2 import asyncio 3 async def show(): return "Eduinq" 4 async def main(): 5 t = asyncio.create_task(show()) 6 print(await t) 7 asyncio.run(main()) View Answer
Correct answer: A — Eduinq
- Which of the following is used for event loop?
View Answer
Correct answer: A — asyncio.get_event_loop()
- What is the output of below code?
1 python 2 import asyncio 3 loop = asyncio.get_event_loop() 4 print(isinstance(loop,asyncio.AbstractEventLoop)) View Answer
Correct answer: A — True
- Which of the following is used for futures?
View Answer
Correct answer: A — asyncio.Future
- What will be printed?
1 python 2 import asyncio 3 f = asyncio.Future() 4 f.set_result("Eduinq") 5 print(f.result()) View Answer
Correct answer: A — Eduinq
- Which of the following is used for queues in asyncio?
View Answer
Correct answer: A — asyncio.Queue
- What is the output of below code?
1 python 2 import asyncio 3 async def main(): 4 q = asyncio.Queue() 5 await q.put("Eduinq") 6 print(await q.get()) 7 asyncio.run(main()) View Answer
Correct answer: A — Eduinq
- Which of the following is used for synchronization in asyncio?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 python 2 import asyncio 3 async def main(): 4 e = asyncio.Event() 5 e.set() 6 print(e.is_set()) 7 asyncio.run(main()) View Answer
Correct answer: A — True
- Which of the following is used for async streams?
View Answer
Correct answer: A — async for
- What is the output of below code?
1 python 2 import asyncio 3 async def main(): 4 async for i in async_iter(): 5 print(i) 6 (Assume async_iter yields 1,2,3) View Answer
Correct answer: A — 1 2 3
- Which of the following is used for async context managers?
View Answer
Correct answer: A — async with
- What will be printed?
1 python 2 import asyncio 3 class Eduinq: 4 async def __aenter__(self): return "Enter" 5 async def __aexit__(self,exc_type,exc,trace): return "Exit" 6 async def main(): 7 async with Eduinq() as e: 8 print(e) 9 asyncio.run(main()) View Answer
Correct answer: A — Enter
- Which of the following is used for async iteration?
View Answer
Correct answer: A — aiter
- What is the output of below code?
1 python 2 class Eduinq: 3 def __aiter__(self): return self 4 async def __anext__(self): return "E" 5 (Iterating once) View Answer
Correct answer: A — E
- Which of the following is used for running tasks concurrently?
View Answer
Correct answer: A — asyncio.wait()
- What will be printed?
1 python 2 import asyncio 3 async def one(): return "E" 4 async def two(): return "duinq" 5 async def main(): 6 done,pending = await asyncio.wait([one(),two()]) 7 for d in done: print(d.result()) 8 asyncio.run(main()) View Answer
Correct answer: A — E duinq
- Which of the following is used for running coroutines until complete?
View Answer
Correct answer: C — loop.run_until_complete()
- What is the output of below code?
1 python 2 import asyncio 3 loop = asyncio.get_event_loop() 4 print(loop.run_until_complete(asyncio.sleep(0))==None) View Answer
Correct answer: A — True
- Which of the following is used for running forever?
View Answer
Correct answer: A — loop.run_forever()
- What will be printed?
1 python 2 import asyncio 3 loop = asyncio.get_event_loop() 4 loop.call_soon(lambda:print("Eduinq")) 5 loop.run_until_complete(asyncio.sleep(0)) View Answer
Correct answer: A — Eduinq
- Which of the following is used for scheduling callbacks?
View Answer
Correct answer: C — Both A and B
- What is the output of below code?
1 python 2 import asyncio 3 loop = asyncio.get_event_loop() 4 loop.call_later(1,lambda:print("Eduinq")) 5 loop.run_until_complete(asyncio.sleep(1.1)) View Answer
Correct answer: A — Eduinq
- Which of the following is used for async subprocesses?
View Answer
Correct answer: A — asyncio.create_subprocess_exec()
- What will be printed?
1 python 2 import asyncio 3 async def main(): 4 proc = await asyncio.create_subprocess_exec("echo","Eduinq") 5 await proc.wait() 6 asyncio.run(main()) View Answer
Correct answer: A — Eduinq
- Which of the following is used for async streams?
View Answer
Correct answer: A — StreamReader, StreamWriter
- What is the output of below code?
1 python 2 import asyncio 3 async def main(): 4 r,w = await asyncio.open_connection("example.com",80) 5 print(isinstance(r,asyncio.StreamReader)) 6 asyncio.run(main()) View Answer
Correct answer: A — True
- Which of the following is used for async tasks cancellation?
View Answer
Correct answer: A — task.cancel()
- What will be printed?
1 python 2 import asyncio 3 async def show(): 4 await asyncio.sleep(5) 5 return "Eduinq" 6 async def main(): 7 t = asyncio.create_task(show()) 8 t.cancel() 9 try: await t 10 except asyncio.CancelledError: print("Cancelled") 11 asyncio.run(main()) View Answer
Correct answer: A — Cancelled
- Which of the following is used for async timeouts?
View Answer
Correct answer: A — asyncio.wait_for()
- What is the output of below code?
1 python 2 import asyncio 3 async def show(): 4 await asyncio.sleep(2) 5 return "Eduinq" 6 async def main(): 7 try: 8 print(await asyncio.wait_for(show(),timeout=1)) 9 except asyncio.TimeoutError: print("Timeout") 10 asyncio.run(main()) View Answer
Correct answer: A — Timeout
- Which of the following is used for async shield?
View Answer
Correct answer: A — asyncio.shield()
- What will be printed?
1 python 2 import asyncio 3 async def show(): 4 await asyncio.sleep(1) 5 return "Eduinq" 6 async def main(): 7 t = asyncio.create_task(show()) 8 print(await asyncio.shield(t)) 9 asyncio.run(main()) View Answer
Correct answer: A — Eduinq
- Which of the following is used for async condition variables?
View Answer
Correct answer: A — asyncio.Condition
- What is the output of below code?
1 python 2 import asyncio 3 async def main(): 4 cond = asyncio.Condition() 5 async with cond: 6 print(isinstance(cond,asyncio.Condition)) 7 asyncio.run(main()) View Answer
Correct answer: A — True
- Which of the following is used for async barriers?
View Answer
Correct answer: B — threading.Barrier
- What will be printed?
1 python 2 import threading 3 b = threading.Barrier(2) 4 print(isinstance(b,threading.Barrier)) View Answer
Correct answer: A — True
- Which of the following is used for async tasks grouping?
View Answer
Correct answer: A — asyncio.TaskGroup
- What is the output of below code?
1 python 2 import asyncio 3 async def main(): 4 async with asyncio.TaskGroup() as tg: 5 tg.create_task(asyncio.sleep(0)) 6 print("Done") 7 asyncio.run(main()) View Answer
Correct answer: A — Done
- Which of the following is used for async run in threads?
View Answer
Correct answer: C — Both A and B
- What will be printed?
1 python 2 import asyncio 3 def show(): return "Eduinq" 4 async def main(): 5 print(await asyncio.to_thread(show)) 6 asyncio.run(main()) View Answer
Correct answer: A — Eduinq