简体   繁体   English

如何在python中的两个进程之间进行通信

[英]How to communicate between two process in python

I am using windows 7 and python 2.7 我正在使用Windows 7和python 2.7

There is process-A. 有过程A。

process-B which is launched through custom url. 通过自定义网址启动的process-B。

My app starts through process-A and it opens a webpage in browser. 我的应用程序从进程A开始,并在浏览器中打开一个网页。 This page does necessary authentication of user and this finally redirect to a url which launches process-B through custom url aligned to it. 该页面对用户进行必要的身份验证,然后最终重定向到一个URL,该URL通过与其对齐的自定义URL启动进程B。

When process-B exits(either success or exception), then process-A should proceed further ie process-A should opens a webpage, then it should wait till process-B is finished, and then continue further. 当进程B退出(成功或异常)时,进程A应该继续进行,即进程A应该打开一个网页,然后等待进程B完成,然后再继续。

So, how process-A know whether process-B is finished or not, ie how to define its waiting period. 因此,进程A如何知道进程B是否完成,即如何定义其等待时间。

You can open a thread in process-A to check if process-B has been started with a simple while loop. 您可以在进程A中打开一个线程,以检查进程B是否已通过简单的while循环启动。 Once process-B is started, you can break the loop and invoke any function you want. 一旦启动了进程B,就可以中断循环并调用所需的任何函数。 With 3pp party wmi , you will be able to know status of process-B. 使用3pp party wmi ,您将能够知道进程B的状态。 For example: 例如:

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import wmi

c = wmi.WMI()

for process in c.Win32_Process():

    # do whatever you want with process
    print 'this is process: ', process

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

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