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
http://twistedmatrix.com/documents/current/core/howto/threading.html):

d = threads.deferToThread(yourSyncCall)
d.addCallback(...)


--
Konrads Smelkovs
Applied IT sorcery.


On Thu, Apr 22, 2010 at 9:06 AM, Andrey Fedorov <anfedo...@gmail.com> wrote:

> 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 :)
>
> 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?
>
> - Andrey
>
>
> On Thu, Apr 22, 2010 at 12:40 AM, Alexandre Quessy 
> <alexan...@quessy.net>wrote:
>
>> Hello Andrey,
>> May I recommend you to look at Twisted Words? There are plenty of IRC
>> tools there.
>>
>> Regards,
>> Alex
>>
>>
>> 2010/4/21 Andrey Fedorov <anfedo...@gmail.com>:
>> > I'm trying to write a dead-simple interface for an IRC client library,
>> like
>> > so:
>> >     import simpleirc
>> >     connection = simpleirc.Connect('irc.freenode.net', 6667)
>> >     channel = connection.join('foo')
>> >     find_command = re.compile(r'google ([a-z]+)').findall
>> >     for msg in channel:
>> >         for t in find_command(msg):
>> >             channel.say("http://google.com/search?q=%s"; % t)
>> > Working from the example in the docs, I'm running into trouble with the
>> > callbacks (the code is a bit lengthy, so I pasted it here). The problem
>> is
>> > that the call to channel.__next__ needs to be returned when the
>> > callback <IRCClient instance>.privmsg is called, there doesn't seem to
>> be a
>> > clean option of doing that. I could try to use exceptions or threads,
>> but
>> > that seems like the wrong thing here, is there a simpler (blocking?) way
>> of
>> > using a twisted reactor that would make this possible?
>> > Cheers,
>> > Andrey
>> >
>> > On Wed, Apr 21, 2010 at 10:00 PM, César García <cel...@gmail.com>
>> wrote:
>> >>
>> >> +1 Yes, it's great!!
>> >>
>> >> 2010/4/21 Kevin Horn <kevin.h...@gmail.com>
>> >>>
>> >>> This blog series is also totally rock-a-licious.
>> >>>
>> >>> http://krondo.com/blog/?page_id=1327
>> >>
>> >>
>> >> --
>> >> http://celord.blogspot.com/
>> >>
>> >> _______________________________________________
>> >> Twisted-Python mailing list
>> >> Twisted-Python@twistedmatrix.com
>> >> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>> >>
>> >
>> >
>> > _______________________________________________
>> > Twisted-Python mailing list
>> > Twisted-Python@twistedmatrix.com
>> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>> >
>> >
>>
>>
>>
>> --
>> Alexandre Quessy
>> http://alexandre.quessy.net/
>>
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python@twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to