How to implement a blocking API?

42 views
Skip to first unread message

Thomas Güttler

unread,
Dec 5, 2013, 8:12:08 AM12/5/13
to python...@googlegroups.com
I want to implement a blocking API, but inside I want to use the async pulsar.

Example:

def send_data_to_server_and_wait_for_reply(data_for_server):
   ....

The caller of the above method should not be aware of any pulsar internals. The method
should block until the result is ready.

Regards,
  Thomas

lsbardel

unread,
Dec 6, 2013, 4:14:47 AM12/6/13
to python...@googlegroups.com
Pulsar 0.7 has a  patchy support for synchronous API.
The 0.8 release, currently under development, has improved enormously how synchronous calls are handled and allows to use pulsar internals with any synchronous code.
I will push to the dev branch the 0.8 release very soon.

In the mean time you can try the following:

* in your function create a new event loop
     
     from pulsar.utils.pep import new_event_loop
     loop = new_event_loop(iothreadloop=False)

* use this loop to execute pulsar asynchronous internals via the ``run_until_complete`` method.

Reply all
Reply to author
Forward
0 new messages