Coder Social home page Coder Social logo

Comments (2)

ahopkins avatar ahopkins commented on September 24, 2024

I am not entirely sure what you are trying to achieve. Maybe main_process_start?

https://sanicframework.org/en/guide/basics/listeners.html

from sanic-guide.

gclm avatar gclm commented on September 24, 2024

no way. This seems to be configured every time the worker is created. At present, an error is still reported.
config code:

@app.listener("main_process_start")
async def init_processor(app, loop):
    mp.set_start_method('spawn')
    app.processor = Processor(MODEL_WEIGHTS, MODEL_LABELS)

error message:

[2021-12-02 16:36:56 +0800] [64614] [ERROR] Exception occurred while handling uri: 'http://localhost:8000/predict/file'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    class Sanic(BaseSanic, metaclass=TouchUpMeta):
  File "/opt/projects/ai-server/server.py", line 29, in predict_file
    result = app.processor.process(img)
  File "/opt/projects/ai-server/models/Detect.py", line 82, in process
    img = self.pre_processor(image)
  File "/opt/projects/ai-server/models/Detect.py", line 74, in pre_processor
    img = torch.from_numpy(img).to(self.device)
  File "/home/breakfox/anaconda3/envs/ai-server/lib/python3.9/site-packages/torch/cuda/__init__.py", line 204, in _lazy_init
    raise RuntimeError(
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
Exception occurred while handling uri: 'http://localhost:8000/predict/file'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    class Sanic(BaseSanic, metaclass=TouchUpMeta):
  File "/opt/projects/ai-server/server.py", line 29, in predict_file
    result = app.processor.process(img)
  File "/opt/projects/ai-server/models/Detect.py", line 82, in process
    img = self.pre_processor(image)
  File "/opt/projects/ai-server/models/Detect.py", line 74, in pre_processor
    img = torch.from_numpy(img).to(self.device)
  File "/home/breakfox/anaconda3/envs/ai-server/lib/python3.9/site-packages/torch/cuda/__init__.py", line 204, in _lazy_init
    raise RuntimeError(
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

error message docs: https://discuss.pytorch.org/t/not-using-multiprocessing-but-getting-cuda-error-re-forked-subprocess/54610
How to configure it in this case?

from sanic-guide.

Related Issues (20)

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.