简体   繁体   中英

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

Background:

  • One process using python code.interact() that created an interactive shell
  • Have something running in the interactive shell, a job generating a list of credentials and saved to a variable.

Issue: For some reason, the shell hang and cannot finish

Question: Is it possible to retrieve the variable that saved in the interactive 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.

Define a dict data={} before starting the interactive session, then pass it as a local 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM