import threading from functools import wraps from pathlib import Path from django.conf import settings from django.http import HttpResponse from rest_framework.decorators import action from rest_framework.request import Request from rest_framework.response import Response from rest_framework.viewsets import ViewSet def sync_lock_线程锁( lock ): def decorator( fn ): @wraps( fn ) def wrapper( *args, **kwargs ): with lock: return fn( *args, **kwargs ) return wrapper return decorator class 网页端验证文件接口ViewSets( ViewSet ): lock = threading.Lock( ) # @sync_lock_线程锁( lock=lock ) def 网页端验证文件接口( self, request: Request ): pass print( "=======================" ) auth_text = Path( settings.BASE_DIR ).joinpath( "django_web_微信开放平台应用用户登陆/0p7rS8xxjR.txt" ).read_text( ) print( auth_text ) return HttpResponse( content=auth_text )