pycharm的插件pylint报错:java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-s...

本文探讨了PyCharm中使用Pylint插件时遇到的Write-unsafe context错误,详细分析了错误原因及可能的解决方案,建议调整Pylint设置以避免实时扫描无权限目录。

java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any"). See TransactionGuard documentation for details.
  current modality=ModalityState.NON_MODAL
  known modalities:
    ModalityState.NON_MODAL, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog12,1874,-117,631x767,invalid,hidden,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Push Commits,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=,rootPaneCheckingEnabled=true]]}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog33,2083,205,633x213,invalid,hidden,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Move,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=,rootPaneCheckingEnabled=true]]}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog23,2083,205,633x213,invalid,hidden,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Move,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=,rootPaneCheckingEnabled=true]]}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
    at com.intellij.openapi.application.TransactionGuardImpl.assertWriteActionAllowed(TransactionGuardImpl.java:232)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.a(FileEditorManagerImpl.java:844)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:652)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:665)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4(FileEditorManagerImpl.java:960)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl3(FileEditorManagerImpl.java:782)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.a(FileEditorManagerImpl.java:764)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.a(CoreCommandProcessor.java:139)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:97)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:87)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:73)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl2(FileEditorManagerImpl.java:764)
    at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileWithProviders(FileEditorManagerImpl.java:695)
    at com.intellij.openapi.fileEditor.ex.FileEditorManagerEx.openFile(FileEditorManagerEx.java:139)
    at com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel.scrollToError(PylintToolWindowPanel.java:315)
    at com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel.access$200(PylintToolWindowPanel.java:77)
    at com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel$ToolWindowSelectionListener.valueChanged(PylintToolWindowPanel.java:406)
    at javax.swing.JTree.fireValueChanged(JTree.java:2927)
    at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3391)
    at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:635)
    at com.intellij.ui.treeStructure.Tree$MySelectionModel.fireValueChanged(Tree.java:672)
    at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1093)
    at javax.swing.tree.DefaultTreeSelectionModel.removeSelectionPaths(DefaultTreeSelectionModel.java:502)
    at javax.swing.JTree.removeDescendantSelectedPaths(JTree.java:3723)
    at javax.swing.JTree$TreeModelHandler.treeStructureChanged(JTree.java:3828)
    at javax.swing.tree.DefaultTreeModel.fireTreeStructureChanged(DefaultTreeModel.java:580)
    at javax.swing.tree.DefaultTreeModel.nodeStructureChanged(DefaultTreeModel.java:365)
    at com.leinardi.pycharm.pylint.toolwindow.ResultTreeModel.clear(ResultTreeModel.java:56)
    at com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel.displayInProgress(PylintToolWindowPanel.java:471)
    at com.leinardi.pycharm.pylint.checker.UiFeedbackScannerListener.lambda$scanStarting$0(UiFeedbackScannerListener.java:41)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:781)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:722)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

 

可能的解决办法是,修改pylint的设置,不要实时扫描所有的目录,因为有些目录“Scratches and Consoles”,估计插件没有写权限

 

转载于:https://www.cnblogs.com/shengulong/p/9836395.html

### PyCharm 安装 Conda 环境时 `java.lang.Throwable` 错误解决方案 当在 PyCharm 中配置 Conda 环境时遇到 `java.lang.Throwable: Write-unsafe context! Model changes are allowed from ...` 类型的错误,通常是因为 IDE 的某些操作违反了其内部线程安全机制。以下是详细的分析和解决方法: #### 1. **调整 Pylint 插件设置** 如果 pylint 插件正在尝试访问无写权限的目录(例如 “Scratches and Consoles”),可能会触发此异常。可以通过禁用 pylint 对特定文件夹或整个项目的实时扫描来解决问题。 进入 PyCharm 设置路径如下: - 打开菜单栏中的 `File -> Settings -> Tools -> Python Integrated Tools`。 - 将默认的代码质量工具更改为其他选项或者完全关闭 pylint 实时检测功能[^1]。 #### 2. **重新加载项目索引** 有时该问题是由于缓存损坏引起的。可以清除并重建项目索引来修复潜在问题: ```bash rm -rf .idea/ ``` 运行上述命令删除 `.idea/` 文件夹后重启 PyCharm 并重新导入项目即可恢复正常的索引状态。 #### 3. **验证 JDK 版本兼容性** 确保使用的 JetBrains Runtime 或者自定义指定给 PyCharm 使用的 JDK 是最新版本并与当前操作系统匹配良好。旧版JDK可能存在一些已知缺陷导致此类崩溃行为发生。前往官方网站下载适合您系统的最新稳定release版本进行替换测试看能否消除故障现象。 #### 4. **检查 Conda 路径及权限** 确认所选 conda interpreter 是否具有足够的读取/执行权利以及正确指向目标虚拟env位置;另外还需注意是否存在跨盘符挂载情况造成额外复杂度影响正常工作流程。 ```python import sys print(sys.executable) ``` 通过以上脚本打印出来的解释器绝对路径进一步排查具体定位到哪个conda env被激活使用当中去,并手动赋予必要目录适当的安全属性以便顺利加载依赖库资源完成初始化过程而不会抛出类似的 runtime exception. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值