Is it possible to block a code in view from execution by all users accessing the view while it is being executed by a single user? Kind of single-thread view.
I need it because i generate the python executable with pyinstaller in this view and passing a username into the executable through the config file.
For example:
class CliConfig(APIView):
    def get(self, request, format=None):
        try:
            config['DEFAULT']['username'] = request.user
            #make a build with pyinstaller
            bin_file = open(*generated filepath *, 'rb')
            response = Response(FileWrapper(bin_file), content_type='application/octet-stream')
            response['Content-Disposition'] = 'attachment; filename="%s"' % '*filename*'
            return response
        finally:
            config['DEFAULT']['username'] = ''
So, basically what i want is to generate a python executable which will have a unique username it it's settings, in django rest framwork APIView.  I don't see other approach except passing the username through the settings file. If there is a way - would appreciate an advise.
python 3.6.5, djangorestframework==3.8.2, pyinstaller==3.3.1