Search in sources :

Example 1 with ShellId

use of org.python.pydev.core.ShellId in project Pydev by fabioz.

the class AbstractInterpreterManager method setInfos.

/* (non-Javadoc)
     * @see org.python.pydev.core.IInterpreterManager#setInfos(org.python.pydev.core.IInterpreterInfo[], java.util.Set, org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
public void setInfos(IInterpreterInfo[] infos, Set<String> interpreterNamesToRestore, IProgressMonitor monitor) {
    // Set the string to persist!
    String s = AbstractInterpreterManager.getStringToPersist(infos);
    prefs.put(getPreferenceName(), s);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        String message = e.getMessage();
        if (message == null || message.indexOf("File name not specified") == -1) {
            Log.log(e);
        }
    }
    IInterpreterInfo[] interpreterInfos;
    try {
        synchronized (this.lock) {
            modificationStamp += 1;
            clearInterpretersFromPersistedString();
            persistedString = s;
            // After setting the preference, get the actual infos (will be recreated).
            interpreterInfos = internalRecreateCacheGetInterpreterInfos();
            this.restorePythopathForInterpreters(monitor, interpreterNamesToRestore);
            for (InterpreterInfo info : this.exeToInfo.values()) {
                try {
                    ISystemModulesManager modulesManager = info.getModulesManager();
                    Object pythonPathHelper = modulesManager.getPythonPathHelper();
                    if (!(pythonPathHelper instanceof PythonPathHelper)) {
                        continue;
                    }
                    PythonPathHelper pathHelper = (PythonPathHelper) pythonPathHelper;
                    List<String> pythonpath = pathHelper.getPythonpath();
                    if (pythonpath == null || pythonpath.size() == 0) {
                        continue;
                    }
                    modulesManager.save();
                } catch (Throwable e) {
                    Log.log(e);
                }
            }
        }
        // Now, last step is updating the natures (the call must NOT be locked in this case).
        this.restorePythopathForNatures(monitor);
        // And in jython, changing the classpath also needs to restore it.
        for (IInterpreterInfo interpreter : interpreterInfos) {
            for (ShellId id : AbstractShell.getAllShellIds()) {
                AbstractShell.stopServerShell(interpreter, id);
            }
        }
        IInterpreterManagerListener[] managerListeners = listeners.getListeners();
        for (IInterpreterManagerListener iInterpreterManagerListener : managerListeners) {
            iInterpreterManagerListener.afterSetInfos(this, interpreterInfos);
        }
    } finally {
        AbstractShell.restartAllShells();
    }
    // In the regular process we do not create the global indexing for forced builtins, thus, we schedule a process
    // now which will be able to do that when checking if things are correct in the configuration.
    SyncSystemModulesManagerScheduler syncScheduler = DefaultSyncSystemModulesManagerScheduler.get();
    if (syncScheduler != null && interpreterNamesToRestore != null && interpreterNamesToRestore.size() > 0) {
        ArrayList<IInterpreterInfo> lst = new ArrayList<>(interpreterNamesToRestore.size());
        for (IInterpreterInfo info : interpreterInfos) {
            if (interpreterNamesToRestore.contains(info.getExecutableOrJar())) {
                lst.add(info);
            }
        }
        syncScheduler.addToCheck(this, lst.toArray(new IInterpreterInfo[lst.size()]));
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) ArrayList(java.util.ArrayList) PythonPathHelper(org.python.pydev.ast.codecompletion.revisited.PythonPathHelper) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) ShellId(org.python.pydev.core.ShellId) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManagerListener(org.python.pydev.core.IInterpreterManagerListener) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) SyncSystemModulesManagerScheduler(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler) DefaultSyncSystemModulesManagerScheduler(org.python.pydev.ast.codecompletion.revisited.DefaultSyncSystemModulesManagerScheduler)

Example 2 with ShellId

use of org.python.pydev.core.ShellId in project Pydev by fabioz.

the class PyEdit method init.

/**
 * Initializes everyone that needs document access
 */
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
    try {
        super.init(site, input);
        final IDocument document = getDocument(input);
        // check the document partitioner (sanity check / fix)
        PyPartitionScanner.checkPartitionScanner(document);
        // Also adds Python nature to the project.
        // The reason this is done here is because I want to assign python
        // nature automatically to any project that has active python files.
        final IPythonNature nature = addNature(input);
        // we also want to initialize our shells...
        // we use 2: one for the main thread and one for the other threads.
        // just preemptively start the one for the main thread.
        final ShellId mainThreadShellId = AbstractShell.getShellId();
        Thread thread2 = new Thread() {

            @Override
            public void run() {
                try {
                    try {
                        AbstractShell.getServerShell(nature, mainThreadShellId);
                    } catch (RuntimeException e1) {
                    }
                } catch (Exception e) {
                }
            }
        };
        thread2.setName("Shell starter");
        thread2.start();
        // listen to changes in TAB_WIDTH preference
        prefListener = createPrefChangeListener(this);
        this.getIndentPrefs().addTabChangedListener(this);
        resetForceTabs();
        PyDevUiPrefs.getChainedPrefStore().addPropertyChangeListener(prefListener);
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    // let's do that in a thread, so that we don't have any delays in setting up the editor
                    pyEditScripting = new PyEditScripting();
                    addPyeditListener(pyEditScripting);
                } finally {
                    // if it fails, still mark it as finished.
                    markInitFinished();
                }
            }
        };
        Thread thread = new Thread(runnable);
        thread.setName("PyEdit initializer");
        thread.start();
    } catch (Throwable e) {
        // never fail in the init
        Log.log(e);
    }
}
Also used : PyEditScripting(org.python.pydev.editor.scripting.PyEditScripting) ShellId(org.python.pydev.core.ShellId) IPythonNature(org.python.pydev.core.IPythonNature) IDocument(org.eclipse.jface.text.IDocument) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SyntaxErrorException(org.python.pydev.core.docutils.SyntaxErrorException) BadLocationException(org.eclipse.jface.text.BadLocationException) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) NotConfiguredInterpreterException(org.python.pydev.core.NotConfiguredInterpreterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.python.pydev.parser.jython.ParseException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) RunInUiThread(org.python.pydev.shared_ui.utils.RunInUiThread)

Example 3 with ShellId

use of org.python.pydev.core.ShellId in project Pydev by fabioz.

the class ShellsContainer method restartAllShells.

/**
 * Restarts all the shells and clears any related cache.
 *
 * @return an error message if some exception happens in this process (an empty string means all went smoothly).
 */
public static String restartAllShells() {
    String ret = "";
    synchronized (shells) {
        try {
            if (DebugSettings.DEBUG_CODE_COMPLETION) {
                org.python.pydev.shared_core.log.ToLogFile.toLogFile("Restarting all shells and clearing caches...", AbstractShell.class);
            }
            for (Map<ShellId, AbstractShell> val : shells.values()) {
                for (AbstractShell val2 : val.values()) {
                    if (val2 != null) {
                        val2.endIt();
                    }
                }
                IInterpreterManager[] interpreterManagers = InterpreterManagersAPI.getAllInterpreterManagers();
                for (IInterpreterManager iInterpreterManager : interpreterManagers) {
                    if (iInterpreterManager == null) {
                        // Should happen only on testing...
                        continue;
                    }
                    try {
                        iInterpreterManager.clearCaches();
                    } catch (Exception e) {
                        Log.log(e);
                        ret += e.getMessage() + "\n";
                    }
                }
                // Clear the global modules cache!
                ModulesManager.clearCache();
            }
        } catch (Exception e) {
            Log.log(e);
            ret += e.getMessage() + "\n";
        }
    }
    return ret;
}
Also used : ShellId(org.python.pydev.core.ShellId) IInterpreterManager(org.python.pydev.core.IInterpreterManager) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) JDTNotAvailableException(org.python.copiedfromeclipsesrc.JDTNotAvailableException) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Aggregations

ShellId (org.python.pydev.core.ShellId)3 CoreException (org.eclipse.core.runtime.CoreException)2 MisconfigurationException (org.python.pydev.core.MisconfigurationException)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 DeviceResourceException (org.eclipse.jface.resource.DeviceResourceException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 PartInitException (org.eclipse.ui.PartInitException)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1 JDTNotAvailableException (org.python.copiedfromeclipsesrc.JDTNotAvailableException)1 DefaultSyncSystemModulesManagerScheduler (org.python.pydev.ast.codecompletion.revisited.DefaultSyncSystemModulesManagerScheduler)1 PythonPathHelper (org.python.pydev.ast.codecompletion.revisited.PythonPathHelper)1 SyncSystemModulesManagerScheduler (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IInterpreterManager (org.python.pydev.core.IInterpreterManager)1 IInterpreterManagerListener (org.python.pydev.core.IInterpreterManagerListener)1 IPythonNature (org.python.pydev.core.IPythonNature)1 ISystemModulesManager (org.python.pydev.core.ISystemModulesManager)1