Synchronous API to DelugeRPC ?

Suggestions and discussion of future versions
Post Reply
aidos
Member
Member
Posts: 20
Joined: Tue Nov 24, 2009 9:58 pm

Synchronous API to DelugeRPC ?

Post by aidos »

Hello everyone,

I'm currently developing a little script for my own purpose that needs to control Deluge. I figured I would use the RPC API, but it's entirely asynchronous, because of its use of Twisted deferreds. I had a look on the interwebs to see if there was a way to wait on deferreds, but couldn't find anything. This is too bad, because having to do asynchronous programming makes my code waaaay more complicated than it needs to be (I pretty much have to code a state machine just to do connect -> get ids -> get status). There used to be a synchronous client, and that was awesome for my purpose, is it still in there somewhere ? I had a look through Deluge sources and couldn't find it.

So I guess my questions are : is there still a synchronous API to the deluge RPC, and if not, is there a way to "make" the deferred API synchronous (even a ugly hack, I don't care, this is not production code) ?

Thanks!
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: Synchronous API to DelugeRPC ?

Post by johnnyg »

There's currently no synchronous API.
Check out: http://twistedmatrix.com/documents/8.2. ... eCallbacks

Whichever way you decide to go, feel free to ask for help.
aidos
Member
Member
Posts: 20
Joined: Tue Nov 24, 2009 9:58 pm

Re: Synchronous API to DelugeRPC ?

Post by aidos »

Ah that's clever, hadn't thought of that. It does address my issue with having tons of functions that hardly do anything. It doesn't address my issue with "asynchronousness" though, but if there's nothing else, I'll make do.

Just curious, why did you drop the synchronous API ? do you plan on putting it back in eventually?

Anyway, thanks for the help, much appreciated.
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: Synchronous API to DelugeRPC ?

Post by johnnyg »

How doesn't it address your issue? The function will now block until the deferred has been fired.

In regards to the synchronous API, it wasn't so much that it got dropped, rather that the DelugeRPC got rewritten and it didn't.

There's currently no plans to write a synchronous API, although that doesn't mean it will never get done.
aidos
Member
Member
Posts: 20
Joined: Tue Nov 24, 2009 9:58 pm

Re: Synchronous API to DelugeRPC ?

Post by aidos »

Sorry, I posted without actually testing it, I thought I had figured what it did, but clearly didn't. At first I thought the trick was simply to use the generator pattern to avoid creating a bunch of callbacks function. Anyway I finally understood how this thing works, but honestly why does it have to be so complicated... why not just have a wait() method on Deferred, instead of using decorators and generators and returns through Exceptions... Twisted sure deserves its name...

Well anyhoo, after much trial and error, I got it to work, and I learnt a thing or two about Python, so many thanks :)
Post Reply