public static @NotNull List<PyPackage> refreshAndGetPackagesModally(@NotNull Sdk sdk) {

    final Application app = ApplicationManager.getApplication();
    assert !(app.isWriteAccessAllowed()) :
      "This method can't be called on WriteAction because " +
      "refreshAndGetPackages would be called on AWT thread in this case (see runProcessWithProgressSynchronously) " +
      "and may lead to freeze";


    final Ref<List<PyPackage>> packagesRef = Ref.create();
    final Throwable callStacktrace = new Throwable();
    LOG.debug("Showing modal progress for collecting installed packages", new Throwable());
    PyUtil.runWithProgress(null, PyBundle.message("sdk.scanning.installed.packages"), true, false, indicator -> {
      if (PythonSdkUtil.isDisposed(sdk)) {
        packagesRef.set(Collections.emptyList());
        return;
      }

      indicator.setIndeterminate(true);
      try {
        final PyPackageManager manager = PyPackageManager.getInstance(sdk);
        packagesRef.set(manager.refreshAndGetPackages(false));
      }
      catch (ExecutionException e) {
        packagesRef.set(Collections.emptyList());
        e.initCause(callStacktrace);
        LOG.warn(e);
      }
    });
    return packagesRef.get();
  }
public static @NotNull List<PyPackage> refreshAndGetPackagesModally(@NotNull Sdk sdk)