You can execute blocking call at any time of your pleasing. It will predictable block all execution paths. Typical wrapper around blocking calls is thread. Something like this (from <a href="http://twistedmatrix.com/documents/current/core/howto/threading.html">http://twistedmatrix.com/documents/current/core/howto/threading.html</a>):<br>
<br><span><pre class="python"><span class="py-src-variable">d</span> = <span class="py-src-variable">threads</span>.<span class="py-src-variable">deferToThread</span>(yourSyncCall)<br>d.addCallback(...)<br></pre></span><br clear="all">
--<br>Konrads Smelkovs<br>Applied IT sorcery.<br>
<br><br><div class="gmail_quote">On Thu, Apr 22, 2010 at 9:06 AM, Andrey Fedorov <span dir="ltr"><<a href="mailto:anfedorov@gmail.com">anfedorov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Thanks! The main reason for the question, though, is just curiosity from playing with and learning the Twisted API, not necessarily getting the example working :)<div><br></div><div>A more direct question would have been - is there a Twisted reactor which provides a blocking call instead of a callback? Is there an accepted "best" way of wrapping an non-blocking async API with callbacks into a blocking synchronous one?</div>
<div><br></div><div><font color="#888888">- Andrey</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Thu, Apr 22, 2010 at 12:40 AM, Alexandre Quessy <span dir="ltr"><<a href="mailto:alexandre@quessy.net" target="_blank">alexandre@quessy.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello Andrey,<br>
May I recommend you to look at Twisted Words? There are plenty of IRC<br>
tools there.<br>
<br>
Regards,<br>
Alex<br>
<br>
<br>
2010/4/21 Andrey Fedorov <<a href="mailto:anfedorov@gmail.com" target="_blank">anfedorov@gmail.com</a>>:<br>
<div><div></div><div>> I'm trying to write a dead-simple interface for an IRC client library, like<br>
> so:<br>
> import simpleirc<br>
> connection = simpleirc.Connect('<a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a>', 6667)<br>
> channel = connection.join('foo')<br>
> find_command = re.compile(r'google ([a-z]+)').findall<br>
> for msg in channel:<br>
> for t in find_command(msg):<br>
> channel.say("<a href="http://google.com/search?q=%s" target="_blank">http://google.com/search?q=%s</a>" % t)<br>
> Working from the example in the docs, I'm running into trouble with the<br>
> callbacks (the code is a bit lengthy, so I pasted it here). The problem is<br>
> that the call to channel.__next__ needs to be returned when the<br>
> callback <IRCClient instance>.privmsg is called, there doesn't seem to be a<br>
> clean option of doing that. I could try to use exceptions or threads, but<br>
> that seems like the wrong thing here, is there a simpler (blocking?) way of<br>
> using a twisted reactor that would make this possible?<br>
> Cheers,<br>
> Andrey<br>
><br>
> On Wed, Apr 21, 2010 at 10:00 PM, César García <<a href="mailto:celord@gmail.com" target="_blank">celord@gmail.com</a>> wrote:<br>
>><br>
>> +1 Yes, it's great!!<br>
>><br>
>> 2010/4/21 Kevin Horn <<a href="mailto:kevin.horn@gmail.com" target="_blank">kevin.horn@gmail.com</a>><br>
>>><br>
>>> This blog series is also totally rock-a-licious.<br>
>>><br>
>>> <a href="http://krondo.com/blog/?page_id=1327" target="_blank">http://krondo.com/blog/?page_id=1327</a><br>
>><br>
>><br>
>> --<br>
>> <a href="http://celord.blogspot.com/" target="_blank">http://celord.blogspot.com/</a><br>
>><br>
>> _______________________________________________<br>
>> Twisted-Python mailing list<br>
>> <a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
>> <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Twisted-Python mailing list<br>
> <a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
> <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
><br>
><br>
<br>
<br>
<br>
</div></div><font color="#888888">--<br>
Alexandre Quessy<br>
<a href="http://alexandre.quessy.net/" target="_blank">http://alexandre.quessy.net/</a><br>
</font><div><div></div><div><br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br>