Git Product home page Git Product logo

sanic-jsonrpc's People

Contributors

mon4ter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sanic-jsonrpc's Issues

It is recommended to remove the check of return value or add switch.

eg:

`
@jsonrpc.jrpc
async def sub(a: int, b: int) -> List[Dict[str, int]]:
await asyncio.sleep(0.1)
return [{"a": a, "b": b}]

`
Sub (5,2) is called correctly at this time

2.`

@jsonrpc.jrpc
async def sub(a: int, b: int) -> List[Dict[str, int]]:
await asyncio.sleep(0.1)
return [{"a": a, "b": b, "c": "c"}]

`

Call error at this time.
feshttp.jsonrpc._routing.route.ResultError: invalid call result value [{'a': 5, 'b': 2, 'c': 'c'}]

In my usage scenario, a lot of data is directly read from the database. There is no need to verify the type of return value. I just need to know that it is a Dict

Once verified, some performance will be lost, so I suggest that you can choose to turn on the verification function

help: cancellable rpc

Hi, I made a subclass of SanicJsonrpc to help cancel long-runing-tasks. https://github.com/hyansuper/cancellable-sanic-jsonrpc
the idea is the client issues an request with an unique task id in 'params' field, (not the message id of jsonrpc spec), server then register this id as its task name, then the client can later issue another jsonrpc calling a remote cancel function with the same task id to cancel the previous long-running-task on server, if it's still running. see client_test.py

Basically, it works, but I need some help in my code:

  1. Why the args is duplicated twice, I have to divide it by 2.
  2. When the client issues a cancellation rpc, I want an asyncio.CancelledError be caught and returned to the client coz the client may be still awaiting for result, but instead I got a 'task exception was never retrieved' error on server side.

note: server_test.py requires python3.8 because the asyncio.current_task().set_name() is only added in version3.8

Can you help? Thank you
ps, please ignore my two previous issues.

RuntimeError: Task <Task pending coro=<Jsonrpc._processing() running at ~/site-packages/sanic_jsonrpc/jsonrpc.py:271>> got Future <Future pending> attached to a different loop

hello,mon4ter

I wrote a demo, it is as follows

`
import asyncio

from sanic import Sanic
from sanic_jsonrpc import Jsonrpc

app = Sanic()
jsonrpc = Jsonrpc(app)

@jsonrpc
async def sub(a: int, b: int) -> int:
await asyncio.sleep(0.1)
return a - b

@jsonrpc
async def test() -> str:
await asyncio.sleep(0.1)
return "中文"

if name == 'main':
app.run(host='127.0.0.1', port=8000)
`
Start the service and test that everything is OK!

Report the error of 'different loop' after stopping the service
it is as follows
`
[2020-02-26 18:39:29 +0800] [17605] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
File "/home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic/app.py", line 1167, in run
serve(**server_settings)
File "/home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic/server.py", line 924, in serve
trigger_events(before_stop, loop)
File "/home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic/server.py", line 667, in trigger_events
loop.run_until_complete(result)
File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
File "/home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic_jsonrpc/jsonrpc.py", line 308, in finish_calls
await self._processing_task
File "/home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic_jsonrpc/jsonrpc.py", line 271, in _processing
call = await calls.get()
File "/usr/lib/python3.6/asyncio/queues.py", line 167, in get
yield from getter
RuntimeError: Task <Task pending coro=<Jsonrpc._processing() running at /home/guoyanfeng/virtual/aclients/lib/python3.6/site-packages/sanic_jsonrpc/jsonrpc.py:271>> got Future attached to a different loop

`
After checking, I found that the loop obtained by queue is inconsistent with the app.

Modified code, test correct!
`
self._routes = {}
self._calls = None
self._processing_task = None

    @app.listener('after_server_start')
    async def start_processing(_app, _loop):
        self._calls = Queue(loop=_loop)
        self._processing_task = ensure_future(self._processing())

`
I hope the author can change it in the source code. Thank you

Python 3.9 support

Hello,

Your project looks really interesting and we are checking it out to use it on our next project. However, first thing we noticed is that it doesn't support Python 3.9. Is there any plans on adding that support, expanding the documentation and potentially add more features to it in the future?

Thanks!

A jsonrpc package is missing from the 0.2.1 version and cannot be used.

Hi @mon4ter !

I tested the latest version (0.2.1) after installation and found that there was a 'jsronrpc' package missing.

The packages of the setup file are as follows.

    packages=[
        'sanic_jsonrpc',
        'sanic_jsonrpc._routing',
        'sanic_jsonrpc.models',
    ],

missing 'sanic_jsonrpc.jsonrpc'

I will use version 0.1.1 first.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.