code: def generate_or_read_from_file(key_file='.secret_key', key_length=64):
      
      abspath = os.path.abspath(key_file)
      # check, if key_file already exists
      # if yes, then just read and return key
      if os.path.exists(key_file):
          key = read_from_file(key_file)
          return key
  
      # otherwise, first lock to make sure only one process
      lock = lockutils.external_lock(key_file + ".lock",
                                     lock_path=os.path.dirname(abspath))
      with lock:
          if not os.path.exists(key_file):
              key = generate_key(key_length)
              old_umask = os.umask(0o177)  # Use '0600' file permissions
              with open(key_file, 'w') as f:
                  f.write(key)
              os.umask(old_umask)
          else:
              key = read_from_file(key_file)
          return key
docs: Multiprocess-safe secret key file generator.
  
      Useful to replace the default (and thus unsafe) SECRET_KEY in settings.py
      upon first start. Save to use, i.e. when multiple Python interpreters
      serve the dashboard Django application (e.g. in a mod_wsgi + daemonized
      environment).  Also checks if file permissions are set correctly and
      throws an exception if not.