japronto icon indicating copy to clipboard operation
japronto copied to clipboard

Cannot use a custom Matcher Factory

Open Mayzie opened this issue 6 years ago • 2 comments

Hello!

It currently isn't possible, as far as I can tell, to use a custom Matcher class (or even the Python one in japronto.router.Matcher).

Python just segfaults under asyncio, and ignores the error under uvloop.

My sample code is as follows:

#!/usr/bin/env python

from asyncio import get_event_loop

from japronto import Application
from japronto.router import Router
from japronto.router.matcher import Matcher

def custom_match_request(*args, **kwargs):
    print('In custom_match_request')
    print(dir(args))
    print(dir(kwargs))

app = Application()
app._loop = get_event_loop()

app._router = Router(matcher_factory=Matcher)
app._router.matcher_factory.match_request = custom_match_request

app.run(debug=True)

It does not even enter the function, custom_match_request (given it does not print anything).

Under asyncio (as above), I get:

Accepting connections on http://0.0.0.0:8080
Fatal Python error: Segmentation fault

Current thread 0x00007f823c93f540 (most recent call first):
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 730 in _read_ready
  File "/usr/lib/python3.6/asyncio/events.py", line 145 in _run
  File "/usr/lib/python3.6/asyncio/base_events.py", line 1431 in _run_once
  File "/usr/lib/python3.6/asyncio/base_events.py", line 421 in run_forever
  File "/usr/lib/python3.6/site-packages/japronto/app/__init__.py", line 182 in serve
  File "/usr/lib/python3.6/multiprocessing/process.py", line 93 in run
  File "/usr/lib/python3.6/multiprocessing/process.py", line 258 in _bootstrap
  File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 80 in _launch
  File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 26 in __init__
  File "/usr/lib/python3.6/multiprocessing/context.py", line 277 in _Popen
  File "/usr/lib/python3.6/multiprocessing/context.py", line 223 in _Popen
  File "/usr/lib/python3.6/multiprocessing/process.py", line 105 in start
  File "/usr/lib/python3.6/site-packages/japronto/app/__init__.py", line 228 in _run
  File "/usr/lib/python3.6/site-packages/japronto/app/__init__.py", line 264 in run
  File "./ja_bug.py", line 20 in <module>
Worker crashed on signal SIGSEGV!

Under uvloop (remove the loop overrides above):

Accepting connections on http://0.0.0.0:8080
Exception in callback UVTransport._call_connection_made
handle: <Handle UVTransport._call_connection_made>
Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 52, in uvloop.loop.Handle._run
  File "uvloop/handles/tcp.pyx", line 149, in uvloop.loop.TCPTransport._call_connection_made
  File "uvloop/handles/basetransport.pyx", line 156, in uvloop.loop.UVBaseTransport._call_connection_made
  File "uvloop/handles/basetransport.pyx", line 153, in uvloop.loop.UVBaseTransport._call_connection_made
SystemError: NULL result without error in PyObject_Call

Thanks! 😄

Mayzie avatar Feb 17 '18 12:02 Mayzie