Use These Methods to Make Your Python Concurrent Tasks Perform Better
<h1>Where the Problem Lies</h1>
<p>It has always been the case that Python’s multi-threaded performance has never lived up to expectations because of GIL.</p>
<p>So since version 3.4, Python has introduced the asyncio package to execute IO-bound tasks through concurrency concurrently. After several iterations, the asyncio APIs have worked very well, and the performance of concurrent tasks has improved dramatically compared to the multi-threaded version.</p>
<p>However, there are still many mistakes that programmers make when using asyncio:</p>
<p>One mistake, as shown in the figure below, is to use the await coroutine method directly in a way that changes the call to a concurrent task from asynchronous to synchronous, ultimately losing the concurrency feature.</p>
<p><iframe frameborder="0" height="105" scrolling="no" src="https://towardsdatascience.com/media/895be6533f85fe80fe4b0267d0c4b910" title="mistake_1.py" width="680"></iframe></p>
<p>Another mistake is shown in the figure below, although the programmer realizes that he needs to use <code>create_task</code> to create a task to be executed in the background. However, the following way of waiting for tasks one by one turns the tasks with different timings into an orderly wait.</p>
<p><a href="https://towardsdatascience.com/use-these-methods-to-make-your-python-concurrent-tasks-perform-better-b693b7a633e1">Website</a></p>