<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>jodal.dev - multiprocessing</title>
    <subtitle>Personal blog of Stein Magnus Jodal</subtitle>
    <link rel="self" type="application/atom+xml" href="https://jodal.dev/tags/multiprocessing/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://jodal.dev"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2011-03-20T00:00:00+00:00</updated>
    <id>https://jodal.dev/tags/multiprocessing/atom.xml</id>
    <entry xml:lang="en">
        <title>multiprocessing.Connection is not free</title>
        <published>2011-03-20T00:00:00+00:00</published>
        <updated>2011-03-20T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jodal.dev/2011/03/20/multiprocessing-connection-is-not-free/"/>
        <id>https://jodal.dev/2011/03/20/multiprocessing-connection-is-not-free/</id>
        
        <summary type="html">&lt;p&gt;I’ve
&lt;a href=&quot;https://jodal.dev/2011/03/06/pickling-multiprocessing-connection-objects/&quot;&gt;previously written&lt;/a&gt;
about how to wrap &lt;code&gt;multiprocessing.Connection&lt;/code&gt; objects in a class that makes
&lt;code&gt;Connection&lt;/code&gt; objects picklable, and thus transferable over another
&lt;code&gt;Connection&lt;/code&gt;. That approach is still valid, but don’t use it–or &lt;code&gt;Connection&lt;/code&gt;
objects at all–for lots of use-once-and-throw-away connections.&lt;/p&gt;</summary>
        
    </entry>
    <entry xml:lang="en">
        <title>Pickling multiprocessing Connection objects</title>
        <published>2011-03-06T00:00:00+00:00</published>
        <updated>2011-03-06T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jodal.dev/2011/03/06/pickling-multiprocessing-connection-objects/"/>
        <id>https://jodal.dev/2011/03/06/pickling-multiprocessing-connection-objects/</id>
        
        <summary type="html">&lt;p&gt;For safe message-based communication between threads and processes in Python, I
tend to use
&lt;a rel=&quot;external&quot; href=&quot;http://docs.python.org/library/multiprocessing.html&quot;&gt;multiprocessing&lt;/a&gt;’s
&lt;code&gt;Queue&lt;/code&gt; and &lt;code&gt;Pipe&lt;/code&gt;. A pattern often seen is using a queue for sending messages
from multiple producers to a single consumer.&lt;/p&gt;
&lt;p&gt;When a producer wants a response to its message, I create a &lt;code&gt;Pipe&lt;/code&gt; and
piggy-back one end of the &lt;code&gt;Pipe&lt;/code&gt; (a &lt;code&gt;Connection&lt;/code&gt; object) to the message. I use
Python dicts as messages, and use the string “reply_to” as the dictionary key
for the connection objects.&lt;/p&gt;
&lt;p&gt;When the queue consumer processes a message, it doesn’t know who the sender is
or how to reach him. Though, if the message has an attached &lt;code&gt;Connection&lt;/code&gt;
object, the consumer can–almost magically–respond to the sender, across
thread and process boundaries.&lt;/p&gt;
&lt;p&gt;All good? Nope.&lt;/p&gt;</summary>
        
    </entry>
</feed>
