deep-learning-with-pytorch / dlwpt-code

Code for the book Deep Learning with PyTorch by Eli Stevens, Luca Antiga, and Thomas Viehmann.
https://www.manning.com/books/deep-learning-with-pytorch
4.69k stars 1.98k forks source link

Part 3 Chapter 15 request_batching_server.py #85

Closed Vedant-R closed 2 years ago

Vedant-R commented 2 years ago

Hi,

This is an exceptional solution provided for async deployment and model serving.

I wanted to enquire if there are examples of unit tests for this. I have been continuously struggling with unit tests for sanic async post method with the following error:

async with self.queue_lock:
AttributeError: __aenter__

I am getting this error for the line:

58 async with self.queue_lock:
59        if len(self.queue) >= MAX_QUEUE_SIZE:

The test I am trying:

import json
import pytest
from ..app import app

@pytest.mark.asyncio
async def test_basic_post():
    _, response = await app.asgi_client.post("/predict", data=json.dumps(INPUT), headers=HEADERS)
    print(response)

Please do let me know if anyone has come across this and have a solution.

Vedant-R commented 2 years ago

Got this done, thank you. Closing it