Synchronous API

#1

Hello!

Is there a way to call registered function without using event loop?

It would be easier to debug if simple requests could be executed in ipython console.

0 Likes

#2

Hi Eugene!

Sorry for getting back to you so late.

I’m not too familiar with Python or ipython.

For calling requests from an ipython notebook, if you’re using Crossbar.io, you can use the REST bridge to do so via a HTTP POST.

Here’s code for doing so that we’ve used to define a ‘call’ function that does this:

rpc_url = “http://localhost:8080/call

import requests, json

def call(proc, *args, **kwargs):

payload = {

“procedure”: proc,

“args”: args,

“kwargs”: kwargs

}

r = requests.post(rpc_url, data=json.dumps(payload),

headers={‘content-type’: ‘application/json’})

res = r.json()

return res[‘args’][0]

Hope this helps!

Regards,

Alex

···

Am Montag, 27. Juli 2015 14:44:46 UTC+2 schrieb Eugene Bright:

Hello!

Is there a way to call registered function without using event loop?

It would be easier to debug if simple requests could be executed in ipython console.

0 Likes

#3

You can use the Twisted REPL loop python -m twisted.conch.stdio
That’ll give you an event loop running in your REPL with some freebies (Deferred as first class citizen, etc…)

···

Le lundi 27 juillet 2015 14:44:46 UTC+2, Eugene Bright a écrit :

Hello!

Is there a way to call registered function without using event loop?

It would be easier to debug if simple requests could be executed in ipython console.

0 Likes

#4

I wrote my own wrapper to call registered functions synchronously (via threading and queues), and it was a pain. I probably should have used crochet; it has synchronous wrapper functions that you can put around the asynchronous calls that basically wait for a timeout for the asynchronous call to complete.

http://crochet.readthedocs.org/en/latest/introduction.html

···

On Monday, July 27, 2015 at 5:44:46 AM UTC-7, Eugene Bright wrote:

Hello!

Is there a way to call registered function without using event loop?

It would be easier to debug if simple requests could be executed in ipython console.

0 Likes

#5

Yep, Crochet is cool: https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/wamp/app/crochet

···

Am Montag, 17. August 2015 17:24:00 UTC+2 schrieb Mark Clifton:

I wrote my own wrapper to call registered functions synchronously (via threading and queues), and it was a pain. I probably should have used crochet; it has synchronous wrapper functions that you can put around the asynchronous calls that basically wait for a timeout for the asynchronous call to complete.

http://crochet.readthedocs.org/en/latest/introduction.html

On Monday, July 27, 2015 at 5:44:46 AM UTC-7, Eugene Bright wrote:

Hello!

Is there a way to call registered function without using event loop?

It would be easier to debug if simple requests could be executed in ipython console.

0 Likes