<div>Hi Gavin,�</div><div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
<span><div><div>Hi everyone,<div><br></div><div>I&#39;m interested in running pika&#39;s IOLoop in a thread and I came across this code sample :�<a href="http://cms02.phys.ntu.edu.tw/tracs/env/browser/trunk/messaging/pika/mon.py" target="_blank">http://cms02.phys.ntu.edu.tw/tracs/env/browser/trunk/messaging/pika/mon.py</a></div>
<div><br></div><div>I was wondering why and what could be the advantages of wrapping the callbacks in methods (I can understand the�on_exchange_declared() method that returns a different callback according to thread&#39;s name) ?</div>
</div></div></span></blockquote></div><div>As opposed to doing lambda&#39;s for callbacks? I&#39;m not sure of the context of what you&#39;re comparing callback passing style to.</div></blockquote><div><br></div><div><br>
</div><div>For instance, for this callback: connection.callbacks.add(0, &#39;_on_connection_open&#39;, self._on_connected() , one_shot=True )</div><div><br></div><div>The on_connected callback function in wrapped in the _on_connected() method</div>
<div><br><div>�def _on_connected(self):<br>� � � � def on_connected(connection):<br>� � � � � � <a href="http://pika.log.info">pika.log.info</a>(&quot;%s: connected : %r &quot; % ( self.tag , connection) )<br>� � � � � � connection.channel(self._on_channel_open() )<br>
� � � � � � self.connection = connection<br>� � � � return on_connected�</div><div><br></div><div>Why not:�connection.callbacks.add(0, &#39;_on_connection_open&#39;, self.on_connected , one_shot=True )</div><div><br></div>
<div>�def on_connected(self, connection):<br>� � � � <a href="http://pika.log.info">pika.log.info</a>(&quot;%s: connected : %r &quot; % ( self.tag , connection) )<br>� � � � connection.channel(self._on_channel_open() )<br>
</div></div><div>� � � � self.connection = connection�</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
<span><div><div><div>Another question is why considering multiprocessing over threading in this case ?</div></div></div></span></blockquote></div><div>The IOLoop is a singleton instance and you will run into contention issues and non-thread safe behaviors in use of the IOLoop and event processing.�</div>
<div><br></div><div>I&#39;m not sure what threading buys you in an asynchronous event based model of processing but needless complexity.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></blockquote>
<div>�</div></div><div>My goal is to have an AMQP transport layer inside my application, running &quot;in background&quot;, that handles incoming messages and put them into a python queue. I also want to be able to publish messages from other threads.</div>
<div>I&#39;ve got it to work with threads and python queues in a thread-safe way. I was wondering what could be the benefits for me to use multiprocessing over threading.</div></div>