Unit: Does unit support the python framework of the ASGI specification ? Currently only WSGI is supported?

Created on 20 Dec 2018  ·  6Comments  ·  Source: nginx/unit

Does unit support the python framework of the ASGI specification ? Currently only WSGI is supported?

>

Currently, when I test the asynchronous framework of Python 3 today, I always get debug errors when requesting: Python failed to call the application
is it a code problem or something?

unit config

{
  "listeners": {
    "*:8000": {
      "application": "flaskapp"
    },
    "*:9000": {
      "application": "app"
    }
  },
  "applications": {
    "flaskapp": {
      "type": "python2.7",
      "processes": 1,
      "module": "wsgi",
      "user": "root",
      "group": "root",
      "path": "/apps/py",
      "working_directory": "/apps",
      "home" : "/apps/flask/.venv"
    },
    "app": {
      "type": "python3.7",
      "processes": 1,
      "module": "app",
      "user": "root",
      "group": "root",
      "path": "/apps/py",
      "working_directory": "/apps",
      "home" : "/apps/py/.venv"
    },
    "quart": {
      "type": "python3.7",
      "processes": 1,
      "module": "quart",
      "user": "root",
      "group": "root",
      "path": "/apps/py",
      "working_directory": "/apps",
      "home" : "/apps/py/.venv"
    }
  },
  "access_log": "/var/log/access.log"
}

first test (quart)

https://github.com/pgjones/quart

from quart import Quart

application = Quart(__name__)

@application.route('/')
async def hello():
    return 'hello'

#application.run()

second test (starlette)

https://github.com/encode/starlette

from starlette.applications import Starlette
from starlette.responses import JSONResponse
import uvicorn

application = Starlette()


@application.route('/')
async def homepage(request):
    return JSONResponse({'hello': 'world'})

#if __name__ == '__main__':
#    uvicorn.run(application, host='0.0.0.0', port=9000)

debug info

2018/12/20 09:39:14.732 [debug] 16884#16884 [unit] #25: GET / (0)
2018/12/20 09:39:14.732 [error] 16884#16884 [unit] #25: Python failed to call the application
2018/12/20 09:39:14.732 [debug] 16884#16884 [unit] #25: done: 1
2018/12/20 09:39:14.732 [debug] 16884#16884 [unit] port_send: found port 16779,1 fd 8
2018/12/20 09:39:14.732 [debug] 16884#16884 [unit] port_send(8, 16): 16
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll_wait(18): 1
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll: fd:26 ev:0001 d:7F019C000CE0 rd:5 wr:0
2018/12/20 09:39:14.725 [debug] 16779#16786 timer expire minimum: 114726565:28326565
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 recvmsg(26, -1, 2): 16
2018/12/20 09:39:14.725 [debug] 16779#16786 port 26: message type:1
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00B980)
2018/12/20 09:39:14.725 [debug] 16779#16786 rpc: stream #25 last handler, type 1
2018/12/20 09:39:14.725 [debug] 16779#16786 http request error: 503
2018/12/20 09:39:14.725 [debug] 16779#16786 h1p request header send
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 retain: 3
2018/12/20 09:39:14.725 [debug] 16779#16786 pthread_mutex_lock(56281C11C440) enter
2018/12/20 09:39:14.725 [debug] 16779#16786 pthread_mutex_unlock(56281C11C440) exit
2018/12/20 09:39:14.725 [debug] 16779#16786 app 'app' 56281C11C440 requests queue is empty, keep the port
2018/12/20 09:39:14.725 [debug] 16779#16786 failed to cancel tracking for stream #25
2018/12/20 09:39:14.725 [debug] 16779#16786 mmap buf completion: 7F019C001800 [7F019ADFF000,16384] (sent=1), 16779->16884,0,1
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C000B70 release: 1
2018/12/20 09:39:14.725 [debug] 16779#16786 timer add: 0±50 0:28326565
2018/12/20 09:39:14.725 [debug] 16779#16786 timer change: 28326565±50:1
2018/12/20 09:39:14.725 [debug] 16779#16786 rpc: stream #25 remove first and last pid 16884 registration (7F019C001008)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00B700)
2018/12/20 09:39:14.725 [debug] 16779#16786 rpc: stream #25 free registration
2018/12/20 09:39:14.725 [debug] 16779#16786 recvmsg(26, -1, 2): -1
2018/12/20 09:39:14.725 [debug] 16779#16786 recvmsg(26) not ready
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll 18 set event: fd:26 op:3 ev:80002001
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 http request send error body
2018/12/20 09:39:14.725 [debug] 16779#16786 malloc(136): 7F019C00B700
2018/12/20 09:39:14.725 [debug] 16779#16786 posix_memalign(128, 1024): 7F019C00C980
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 retain: 4
2018/12/20 09:39:14.725 [debug] 16779#16786 h1p request send
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: write
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 conn write fd:13
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 sendbuf: 0, 7F019C00C848, 136
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 sendbuf: 1, 56281A946940, 67
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 writev(13, 2): 203
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 event conn: 203 sent:203
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 timer disable: 0
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 h1p conn sent
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 release: 3
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00B700)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00C980)
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 release: 2
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 http request done
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 http request close handler
2018/12/20 09:39:14.725 [debug] 16779#16786 write(17, 7F019C00C800, 195): 195
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 release: 1
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 h1p request close
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 conf joint 56281C11D700 count: 2
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 h1p keepalive
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 setsockopt(13, 6, TCP_NODELAY): 1
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00A600)
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: read
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 conn read fd:13 rdy:0 cl:0
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 timer add: 28506565±50 180000:28506565
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 timer previous: 28506565±50
2018/12/20 09:39:14.725 [debug] 16779#16786 timers changes: 1
2018/12/20 09:39:14.725 [debug] 16779#16786 timer rbtree insert: 28326565±50
2018/12/20 09:39:14.725 [debug] 16779#16786 timer found minimum: 28326565±50:28326565
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll 18 changes:1
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll_ctl(18): fd:26 op:3 ev:80002001
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll_wait(18) timeout:0
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll_wait(18): 0
2018/12/20 09:39:14.725 [debug] 16779#16786 timer expire minimum: 28326515:28326565
2018/12/20 09:39:14.725 [debug] 16779#16786 timer expire delete: 28326565±50
2018/12/20 09:39:14.725 [debug] 16779#16786 work queue: fast
2018/12/20 09:39:14.725 [debug] 16779#16786 http app release
2018/12/20 09:39:14.725 [debug] 16779#16786 mp 7F019C00BB10 release: 0
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C0041E0)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C002FF0)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00C080)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00B600)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00C500)
2018/12/20 09:39:14.725 [debug] 16779#16786 free(7F019C00BB10)
2018/12/20 09:39:14.725 [debug] 16779#16786 *33 timer found minimum: 28506565±50:28326565
2018/12/20 09:39:14.725 [debug] 16779#16786 epoll_wait(18) timeout:180000
2018/12/20 09:42:14.545 [debug] 16779#16786 epoll_wait(18): 0
2018/12/20 09:42:14.545 [debug] 16779#16786 timer expire minimum: 28506515:28506600
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer expire delete: 28506565±50
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p idle timeout
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: write
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 conn write fd:13
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 sendbuf: 0, 7F019C0031C8, 125
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 send(13, 7F019C0031C8, 125): 125
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 event conn: 125 sent:125
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p conn sent
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 buf completion: 7F019C003180 7F019C0031C8
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p idle timeout response sent
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p shutdown
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p conn closing
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 conn close fd:13, to:0
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: shutdown
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 conn shutdown handler fd:13
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 shutdown(13, 2)
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: close
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 conn close handler fd:13
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer delete: 28506565±50
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer delete: 0±50
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 epoll 18 set event: fd:13 op:2 ev:0
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer add: 0±50 0:28506600
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer change: 28506600±50:1
2018/12/20 09:42:14.545 [debug] 16779#16786 timers changes: 1
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer rbtree insert: 28506600±50
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer found minimum: 28506600±50:28506600
2018/12/20 09:42:14.545 [debug] 16779#16786 epoll 18 changes:1
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 epoll_ctl(18): fd:13 op:2 ev:0
2018/12/20 09:42:14.545 [debug] 16779#16786 epoll_wait(18) timeout:0
2018/12/20 09:42:14.545 [debug] 16779#16786 epoll_wait(18): 0
2018/12/20 09:42:14.545 [debug] 16779#16786 timer expire minimum: 28506550:28506600
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 timer expire delete: 28506600±50
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 conn close timer handler fd:13
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 socket close(13)
2018/12/20 09:42:14.545 [debug] 16779#16786 work queue: fast
2018/12/20 09:42:14.545 [debug] 16779#16786 *33 h1p conn free
2018/12/20 09:42:14.545 [debug] 16779#16786 mp 7F019C00B510 release: 0
2018/12/20 09:42:14.545 [debug] 16779#16786 free(7F019C0029A0)
2018/12/20 09:42:14.545 [debug] 16779#16786 free(7F019C00B180)
2018/12/20 09:42:14.545 [debug] 16779#16786 free(7F019C003080)
2018/12/20 09:42:14.545 [debug] 16779#16786 free(7F019C00B510)
2018/12/20 09:42:14.545 [debug] 16779#16786 listen event count: 2
2018/12/20 09:42:14.545 [debug] 16779#16786 epoll_wait(18) timeout:-1
enhancement

Most helpful comment

I'm agree with @akshaybabloo. There is a start of specifications here.

@VBart Have you rethink about that ? Would that be a lot of work?

All 6 comments

Currently only WSGI is supported as specified by PEP 333 and 3333. No other interfaces are supported right now.

It will be good to have this. Starting from Django 3.0, it will have async features

I'm agree with @akshaybabloo. There is a start of specifications here.

@VBart Have you rethink about that ? Would that be a lot of work?

Any news on this subject ?

Also looking for this feature

Coming soon... Get ready and track #461 issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Madhu1512 picture Madhu1512  ·  4Comments

xiongxin picture xiongxin  ·  5Comments

yujinqiu picture yujinqiu  ·  5Comments

thresheek picture thresheek  ·  4Comments

AkulovNV picture AkulovNV  ·  4Comments