简体   繁体   English

如何将数据从一个python脚本文件发送到pygtk中的另一个

[英]how to send data from one python script file to another in pygtk

I want to send data from one py file ( stuff.py ) to another py file ( start.py ) in pygtk means I want to send data from one window to another window which I will select in 1st. 我想将数据从一个py文件( stuff.py )发送到pygtk中的另一个py文件( start.py ),这意味着我想将数据从一个窗口发送到另一个窗口,该窗口将在1st中进行选择。 so anybody let me know how to send data from one file to another file. 所以有人让我知道如何将数据从一个文件发送到另一个文件。

I am using subprocess . 我正在使用subprocess

subprocess.call('start.py', shell=True)

First of all, you really should be talking about sending data from one PROCESS to another PROCESS—sending data between files doesn't make much sense (unless you're talking about taking content from file1 and copy-pasting it to file2, but that's clearly not what this is about). 首先,您确实应该在谈论将数据从一个过程发送到另一个过程—在文件之间发送数据没有多大意义(除非您正在谈论从文件1中获取内容并将其复制粘贴到文件2中,但这就是显然不是这个意思)。

This is called IPC (Inter-Processes Communication). 这称为IPC(进程间通信)。 There are various ways how to do that; 有多种方法可以做到这一点。 to list a few options: 列出一些选项:

  • one process writes to a file and the other reads from that file 一个进程写入文件,另一个进程从该文件读取
  • one process writes to a named pipe and the other reads from that named pipe (really almost interchangeable with the first option) 一个进程写入一个命名管道,另一个进程从该命名管道读取(与第一个选项几乎可以互换)
  • one process connects to the other over TCP/sockets on a port which the other process listens, and they then begin exchanging TCP packets over a period of time 一个进程通过另一个进程侦听的端口上的TCP /套接字连接到另一个进程,然后它们在一段时间内开始交换TCP数据包
  • the processes share part of the RAM of the computer, so that they can write and read from the same place (this can have very good performance, but I'm afraid it's not that simple on Python due to copy-on-write, which gets triggered super easily, AFAIK) 进程共享计算机RAM的一部分,以便它们可以在同一位置进行读写(这可以有很好的性能,但是由于写时复制,恐怕它在Python上不是那么简单)可以非常轻松地触发,AFAIK)
  • you use a more high-level IPC mechanism such as ZeroMQ, which are also suitable for networking more generally speaking; 您使用更高级的IPC机制(例如ZeroMQ),也更适合于联网。 these take the burden of handling all the low level technical and protocol details off of your shoulders, so if IPC is something you need to handle on a regular bases and in non-trivial tasks, I strongly suggest you look into ZeroMQ or something similar; 这些使您负担了所有低级技术和协议细节的负担,因此,如果IPC是您需要定期处理的日常任务和非平凡任务,那么我强烈建议您研究ZeroMQ或类似的东西。 see http://zeromq.org and http://zeromq.github.io/pyzmq/ for more information on how to get started, should this be the choice for you. 有关如何入门的更多信息,请参见http://zeromq.orghttp://zeromq.github.io/pyzmq/ ,如果这是您的选择。

For more information, see https://en.wikipedia.org/wiki/Inter-process_communication . 有关更多信息,请参见https://en.wikipedia.org/wiki/Inter-process_communication

As to your question about subprocess.call(...) —no, this will just invoke the other file creating a completely new process; 关于您有关subprocess.call(...) -否,这只会调用另一个文件来创建一个全新的进程; this will in no way affect any existing processes, regardless of whether they are spawned from start.py or not. 这将不会影响任何现有进程,无论它们是否从start.py生成。 Also, to my best knowledge, whether your app uses pygtk or not, should be more or less irrelevant to the question of how to do IPC. 同样,据我所知,您的应用程序是否使用pygtk,应该与如何进行IPC的问题或多或少无关。

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

相关问题 将数据从一个 python 文件发送到另一个文件 - Send data from one python file to another 试图将数据从 python 中的一个脚本发送到另一个脚本 - trying to send data from one script in python to another script Python将变量从一个脚本发送到另一个脚本 - Python send variable from one script to another 将变量从一个Python脚本发送到另一个 - Send a Variable from one Python Script to another 如何在python中将此def脚本从一个文件制作到另一个文件 - How to make this def script from one file to another file in python 如何从一个套接字接收数据并将其发送到python中的另一个套接字? - How to recieve data from a one socket and send it to another socket in python? 如果使用zmq接收来自另一个脚本的正确数据,如何将数据发送到一个脚本 - How to send data to one script for as long as correct data from another script is being received using zmq 将数据从 python 页面发送到另一个页面 - Send data from a python page to another one Django 将输入数据从 HTML 文件传递​​到 python 脚本,然后将最终数据发送到另一个 HTML 文件 - Django pass input data from an HTML file to a python script and then send the final data to another HTML file 如何将数据从一个python文件返回到另一个python文件 - How to return data from one python file to another python file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM