简体   繁体   English

是否可以从另一个已经运行的进程加载 python 变量?

[英]Is it possible to load python variable from another already running process?

Background:背景:

  • One process using python code.interact() that created an interactive shell一个使用 python code.interact()创建交互式 shell 的进程
  • Have something running in the interactive shell, a job generating a list of credentials and saved to a variable.在交互式 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.

相关问题 通过命名管道将数据发送到另一个已经运行的 python 进程 - Send data to another already running python process via named pipe 使用Python访问已运行的进程 - Accessing an ALREADY running process, with Python 将值从一个python脚本发送到已经运行的另一个 - Send values from one python script to another one already running 是否有可能将变量从文件导入到另一个文件并进行处理,然后将结果返回到第一个 - is it possible import variable from file to another and process then return the result to the first Python-将参数传递给已经运行的进程 - Python - Passing arguments to an already running process 是否有可能重新启动python multiprocessing中已经终止的进程? - is it possible to restart the already terminated process in python multiprocessing? 如何在 python 的 memory 中映射/加载文件并从另一个进程访问它? - How to mmap/load a file in memory in python and acces to it from another process? 从已经运行的进程创建子进程对象 - create subprocess object from already running process 长时间运行的Python进程,它接受来自另一个非Python进程的输入 - Long-running Python process that accepts inputs from another non-Python process Python从正在运行的脚本中获取变量并传递给另一个Python脚本 - Python get variable from running script and pass to another Python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM