[英]Is it possible to load python variable from another already running process?
Background:背景:
code.interact()
that created an interactive shell一个使用 python code.interact()
创建交互式 shell 的进程Issue: For some reason, the shell hang and cannot finish问题:由于某种原因,shell 挂起并且无法完成
Question: Is it possible to retrieve the variable that saved in the interactive shell?问题:是否可以检索保存在交互式 shell 中的变量?
Ctrl+Z and Kill the process usually will fix the hang issue but I have to rerun it again and lost some already generated information. Ctrl+Z 和终止进程通常会解决挂起问题,但我必须再次重新运行它并丢失了一些已经生成的信息。
Define a dict data={}
before starting the interactive session, then pass it as a local code.interact(local={'data':data})
.在开始交互式会话之前定义一个 dict data={}
,然后将其作为本地code.interact(local={'data':data})
传递。 Save your data in that dict, and all changes will be available after exiting the interactive session.将您的数据保存在该字典中,退出交互式会话后,所有更改都将可用。
This works because interact
doesn't actually start a new process/interpreter.这是有效的,因为interact
实际上并没有启动一个新的进程/解释器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.