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()]));
}
}
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);
}
}
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;
}
Aggregations