简体   繁体   English

python 中是否可以有两个运行相同脚本的独立 shell?

[英]Is it possible to have two separate shells in python that are running the same script?

Essentially what I am looking for is a way to have two shells interacting with one script of the main program (Change variables and all that) and have the other shell see those changes.基本上我正在寻找的是一种让两个 shell 与主程序的一个脚本交互(更改变量和所有这些)并让另一个 shell 看到这些更改的方法。 for example:例如:

shell 1 gets asked with teh input what it would like to add to the list, and types in "apple" shell 1 被要求输入它想添加到列表中的内容,然后输入“apple”

shell 2 who is also running the same script would be able to enter view and see that shell 1 had entered apple to List[1].同样运行相同脚本的 shell 2 将能够进入视图并看到 shell 1 已将 apple 输入到 List[1]。

List = ["Oranges"]
UserInput = input("enter another fruit or 'V' for view")
if UserInput == "V":
    print(List)
else:
    List.append(UserInput)

shell 1 gets asked with the input what it would like to add to the list, and types in "Apples" would see: "enter another fruit or 'V' for view">"Apples" shell 1 被问及要添加到列表中的输入,输入“Apples”会看到:“enter another fruit or 'V' for view”>“Apples”

shell 2 who is also running the same script would be able to enter view and see that shell 1 had entered apple to List.同样运行相同脚本的 shell 2 将能够进入视图并看到 shell 1 已将苹果输入到列表中。 would see: enter another fruit or 'V' for view">"V" [Oranges, Apples]会看到:输入另一个水果或“V”查看“>”V“[橘子,苹果]

for my purposes the data would not have any collisions/errors with overwrite as two people would not be able to edit the same thing not sure if what i have said makes sense but i have tried previously using TKinter as a pop out shell but did not end up working.出于我的目的,数据不会与覆盖发生任何冲突/错误,因为两个人将无法编辑相同的东西不确定我所说的是否有意义但我之前尝试过使用 TKinter 作为弹出窗口 shell 但没有结束工作。

I do not think you will need to go to the extreme with testing via separate shells.我认为您不需要 go 通过单独的 shell 进行测试。 Understandably you want to make sure that when data is accessed that you don't fall into any locking problems.可以理解,您希望确保在访问数据时不会陷入任何锁定问题。 A quick google search will yield many examples of how to do MultiThreading, here's the first result I found: geeksforgeeks.org/multithreading-python-set-1 try this and learn a little about how this works.快速谷歌搜索将产生许多如何执行多线程的示例,这是我找到的第一个结果: geeksforgeeks.org/multithreading-python-set-1试试这个并了解它的工作原理。

Additionally, I would also recommend looking up testing realpython.com/python-testing and how to do this, because you should be able to test your precise situation without having to create two shell windows.此外,我还建议您查看测试realpython.com/python-testing以及如何执行此操作,因为您应该能够测试您的精确情况,而无需创建两个 shell windows。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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