void (@NotNull ProcessHandler process) { Disposable disposable = Disposer.newDisposable(); Disposable a = new Disposable() { @Override public void dispose() { Disposer.dispose(disposable); } }; Disposable b = new Disposable() { @Override public void dispose() { Disposer.dispose(disposable); } }; //noinspection IncorrectParentDisposable Disposer.register(myModule, a); Disposer.register(PythonPluginDisposable.getInstance(myModule.getProject()), b); Disposer.register(disposable, a); Disposer.register(disposable, b); process.addProcessListener(new ProcessListener() { @Override public void processTerminated(@NotNull ProcessEvent event) { Disposer.dispose(disposable); } }, disposable); ApplicationManager.getApplication().getMessageBus().connect(disposable) .subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appWillBeClosed(boolean isRestart) { process.destroyProcess(); } }); }