tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
53 stars 24 forks source link

Non-blocking notifs? #11

Closed byaka closed 9 years ago

byaka commented 9 years ago

is it possible to add another "notify" method, for calling methods without waiting for completion? it will be useful for some specific things, like pushing data to server (with long processing of it, for example adding to db). I'm know, it's break specification, but can be useful like optional extended future.

tcalmant commented 9 years ago

Actually, the (JSON-RPC specification)[http://www.jsonrpc.org/specification#notification] says:

[...] a Notification signifies the Client's lack of interest in the corresponding Response [...] The Server MUST NOT reply to a Notification

Technically, it is possible to start a new thread for each notification in jsonrpclib, to let the long process be done in background. But you won't be able to get any result afterwards. => This would need a relatively small work on jsonrpclib

Another solution would be to create a manager which will queue those calls and associate them to a UUID. That way, you can use a thread pool to control the number of threads, and you could poll a get_result(uid) method to ask for the result regularly. => This could be a utility module in jsonrpclib, but it would require a little more work.

byaka commented 9 years ago

Second solution more flexible, but i'm think it complicate a library's logic.

tcalmant commented 9 years ago

I'll implement the first solution during next week, as it has been marked by a TODO comment a long time ago. The second one will have to wait a little.

byaka commented 9 years ago

U are awesome! Thx

tcalmant commented 9 years ago

Could you try the latest version from the git repository ? It adds support to use a thread pool in the JSON-RPC dispatcher (and server). I haven't added tests yet, as I'll do it next week.

See the server part of the readme file to setup the thread pool.

byaka commented 9 years ago

Big thx for implementing this functional! I can't do really big test with high loading for now, but simple tests work perfect! In past i have some issues with threads and mysql, and when i can i'm try to test this.

tcalmant commented 9 years ago

Final features implemented for this issue:

The ThreadPool class is now tested, no need to keep this opened.