
    <rss 
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:content="http://purl.org/rss/1.0/modules/content/"
      xmlns:atom="http://www.w3.org/2005/Atom"
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:typefully="https://typefully.com/profile"
      version="2.0">
      <channel>
        <title>Eli Wilson (@__daetam__)</title>
        <link>https://typefully.com/__daetam__</link>
        <description>Looking to start a restaurant that prints the menu on garlic toast.  Formerly at the department of magic and spell casting.</description>
        <pubDate>Fri, 04 Nov 2022 16:00:18 GMT</pubDate>
        <lastBuildDate>Fri, 04 Nov 2022 16:00:18 GMT</lastBuildDate>
        <generator>Typefully</generator>
        <image>https://screenshots.typefully.com/screenshot?size=1200x640&amp;url=https://typefully.com/__daetam__/card</image>
        <atom:link href="https://typefully.com/__daetam__" rel="self" type="application/rss+xml"/>
        
    <item>
      <guid>https://typefully.com/__daetam__/executors-in-asyncio-8XZAyZ5</guid>
      <title>Executors in asyncio</title>
      <description>Executors in #asyncio 🧵 I&#39;ve talked before about how asyncio is limited to one coroutine execution at a time. Additionally, CPU-intensive operations will block the asyncio event loop causing other coroutines to be blocked from executing. To get around this, you can use a thread pool or process pool…</description>
      <link>https://typefully.com/__daetam__/executors-in-asyncio-8XZAyZ5</link>
      <pubDate>Fri, 04 Nov 2022 16:00:18 GMT</pubDate>
      <content:encoded><![CDATA[Executors in <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> 🧵<br><br>I've talked before about how asyncio is limited to one coroutine execution at a time. Additionally, CPU-intensive operations will block the asyncio event loop causing other coroutines to be blocked from executing.<br><br>To get around this, you can use a thread pool or process pool executor. Use a thread pool when you can't serialize data between processes AND the synchronous code you're running is network bound. For CPU-bound code, use a process pool.<br><br>A process pool executor works the same way as a thread pool except that you're not limited by the GIL. This makes it the perfect solution for complex computation and other CPU-intensive code. The downside is that any variables passed to the separate process must be serializable.<br><br>Follow me for more <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> tips, tricks, and explanations!<br><br>Bonus: If using <a class="tweet-url username" href="https://twitter.com/datadoghq" data-screen-name="datadoghq" target="_blank" rel="nofollow">@datadoghq</a> as an APM solution, you should use their run_in_executor method. This passes any trace context to the thread/process. <a href="https://github.com/DataDog/dd-trace-py/blob/fb8dfa2f33fff37d21df9728d8386c0260df9744/ddtrace/contrib/asyncio/helpers.py#L37" target="_blank" rel="nofollow">https://github.com/DataDog/dd-trace-py/blob/fb8dfa2f33fff37d21df9728d8386c0260df9744/ddtrace/contrib/asyncio/helpers.py#L37</a> There is a similar method for create_task. <a href="https://github.com/DataDog/dd-trace-py/blob/fb8dfa2f33fff37d21df9728d8386c0260df9744/ddtrace/contrib/asyncio/helpers.py#L76" target="_blank" rel="nofollow">https://github.com/DataDog/dd-trace-py/blob/fb8dfa2f33fff37d21df9728d8386c0260df9744/ddtrace/contrib/asyncio/helpers.py#L76</a><br><br>You can read the unrolled version of this thread here: <a href="https://typefully.com/__daetam__/8XZAyZ5" target="_blank" rel="nofollow">https://typefully.com/__daetam__/8XZAyZ5</a>]]></content:encoded>
      <typefully:post_id>8XZAyZ5</typefully:post_id>
      <typefully:post_type>thread</typefully:post_type>
      <typefully:pinned>false</typefully:pinned>
      null
    </item>
  
    <item>
      <guid>https://typefully.com/__daetam__/what-is-the-python-gil-ZZ5dAAU</guid>
      <title>What is the Python GIL?</title>
      <description>What is the #Python GIL? 🧵 The Global Interpreter Lock is somewhat unique to Python. At a high level, the GIL ensures that only one thread is executing at a time. When improving the performance of your Python application, you can look to threads, processes, and asyncio. The GIL only applies to mult…</description>
      <link>https://typefully.com/__daetam__/what-is-the-python-gil-ZZ5dAAU</link>
      <pubDate>Mon, 24 Oct 2022 18:00:07 GMT</pubDate>
      <content:encoded><![CDATA[What is the <a href="https://twitter.com/search?q=%23Python" title="#Python" class="tweet-url hashtag" target="_blank" rel="nofollow">#Python</a> GIL? 🧵<br><br>The Global Interpreter Lock is somewhat unique to Python. At a high level, the GIL ensures that only one thread is executing at a time. When improving the performance of your Python application, you can look to threads, processes, and asyncio.<br><br>The GIL only applies to multi-threaded applications. For CPU-intensive programs, using threads won't give any advantages and you'll likely see the same performance as a single-threaded application. This is due to CPU-intensive operations holding the GIL until they're done.<br><br>If your application is more I/O heavy, such as making network requests, then threads can provide improved performance. This is similar to how <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> works. For I/O operations, the operating system can wait for the socket to become active again with data and continue operation.<br><br>The main advantage of <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> is the syntax. Creating and managing threads in Python is less than straightforward while using the async/await syntax is similar to that of a synchronous application.<br><br>TL;DR: <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> and threads offer similar performance benefits through concurrency. For CPU-intensive applications, it's necessary to use separate processes to achieve parallel execution.<br><br>Follow me for more <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> tips, tricks, and explanations!<br><br><br>You can read the unrolled version of this thread here: <a href="https://typefully.com/__daetam__/ZZ5dAAU" target="_blank" rel="nofollow">https://typefully.com/__daetam__/ZZ5dAAU</a>]]></content:encoded>
      <typefully:post_id>ZZ5dAAU</typefully:post_id>
      <typefully:post_type>thread</typefully:post_type>
      <typefully:pinned>false</typefully:pinned>
      null
    </item>
  
    <item>
      <guid>https://typefully.com/__daetam__/start-understanding-python-asyncio-NkxCdtt</guid>
      <title>Start understanding Python asyncio</title>
      <description>Let&#39;s try an #asyncio #python thread! 🧵
Start understanding asyncio in python: What is asyncio? It&#39;s a way to run python code concurrently, which gives us a way to write I/O-intensive code in a non-blocking manner. This is generally for networking requests such as HTTP and databases. File I/O isn&#39;t…</description>
      <link>https://typefully.com/__daetam__/start-understanding-python-asyncio-NkxCdtt</link>
      <pubDate>Mon, 17 Oct 2022 18:00:10 GMT</pubDate>
      <content:encoded><![CDATA[Let's try an <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> <a href="https://twitter.com/search?q=%23python" title="#python" class="tweet-url hashtag" target="_blank" rel="nofollow">#python</a> thread! 🧵<br>Start understanding asyncio in python:<br><br>What is asyncio? It's a way to run python code concurrently, which gives us a way to write I/O-intensive code in a non-blocking manner. This is generally for networking requests such as HTTP and databases. File I/O isn't natively supported by OSes (thread for another day).<br><br>Example: I need to do laundry, dishes, and clean. I can do each of these chores serially (one at a time) which is how python code executes by default. Alternatively, I could switch between chores while the machines (washer, dryer, dishwasher, etc.) do some work for us.<br><br>I can start the laundry, then start the dishes, then clean while those are running. After a while, I can decide to take a break and move the laundry to the dryer, and put the dishes away. This is an example of concurrency which is what asyncio is in python.<br><br>Concurrency allows for more efficient use of CPU time. Instead of blocking the main thread while waiting on a network request or database response, that waiting can be done "in the background" and other code can be executed.<br><br>Parallelism is different and allows code to be executed simultaneously. In the previous example of chores, this would be 2 people doing chores at the same time. In Python, this is represented with processes.<br><br>Follow me for more <a href="https://twitter.com/search?q=%23asyncio" title="#asyncio" class="tweet-url hashtag" target="_blank" rel="nofollow">#asyncio</a> tips, tricks, and explanations!<br><br>Bonus: depending on the workload, asyncio/concurrency can be faster than parallelism! For CPU-intensive tasks that aren't I/O bound, such as large calculations, parallelism is the way to go. For anything using a network socket (and even subprocesses), asyncio is the way to go.<br><br>You can read the unrolled version of this thread here: <a href="https://typefully.com/__daetam__/NkxCdtt" target="_blank" rel="nofollow">https://typefully.com/__daetam__/NkxCdtt</a>]]></content:encoded>
      <typefully:post_id>NkxCdtt</typefully:post_id>
      <typefully:post_type>thread</typefully:post_type>
      <typefully:pinned>false</typefully:pinned>
      null
    </item>
  
      </channel>
    </rss>
  