video_stream / cuda_multi_processing_test.py
zmbfeng's picture
test multiple processing actual code
fcbeb17
Raw
History Blame Contribute Delete
830 Bytes
from fastapi import FastAPI, HTTPException,WebSocket, File, UploadFile
import os
import multiprocessing
import torch
app = FastAPI()
os.environ['CUDA_LAUNCH_BLOCKING'] = "1"
@app.get("/")
async def read_root():
return {"Hello": "World"}
def worker():
print(f"Worker process started with PID: {os.getpid()}")
print (__name__)
if __name__ == "app":
print("Main process ID:", os.getpid())
p = multiprocessing.Process(target=worker)
p.start()
p.join()
print("in __main__")
cuda_available = torch.cuda.is_available()
print(f"CUDA Available: {cuda_available}")
if cuda_available:
print(f"Number of CUDA devices: {torch.cuda.device_count()}")
print(f"CUDA Device Name: {torch.cuda.get_device_name(0)}")
else:
print("CUDA is not available. Check your installation.")