Giter Club home page Giter Club logo

Comments (2)

LinkinPF avatar LinkinPF commented on August 15, 2024

张孝家:想法一(不知道对不对,有问题大家指出来)
当我们用cmd.Start()开始启动python程序之后,cmd.Wait()之前,在这两个中间,我们可以从cmd结构体对象中Process对象中Pid字段,提取进程的pid号。然后,可以全局共享切片(保存int类型的切片),将进程的pid号保存到这个共享切片中。当我们ctrl-c的lmp的时候,我们可以捕捉到这个信号,在这个信号处理程序中,对切片中的进程pid号,通过syscall.kill()来杀死线程。用什么保存pid号,其实都可以,如切片、管道、数组、map我感觉都是可以的,但是我更倾向于切片。
想法二(不保存pid号,保存Process)
在cmd结构对象中,有个Process字段(这个字段的类型是
os.Process),我们可以保存这个字段的信息到切片中。还是在cmd.Start()和cmd.Wait()之间来提取。然后,同样在ctrl-c lmp的时候,捕捉信号,在信号处理函数中,遍历切片。通过方法func (p *Process) Kill() error,来杀死进程。

from lmp.

LinkinPF avatar LinkinPF commented on August 15, 2024

张孝家:想法三(这种方法是我比较喜欢的,但是我不知道对不对。)
通过ctx来做这件事情,我们将创建ctx的的事件提前在主线程中做(保存到一个全局变量里面),在我们go execute的的时候,我们通过传入ctx参数,然后创建goroutine,来执行python程序。同样,当我们杀死lmp的时候,捕捉信号。在信号处理函数中,通过ctx.done()获取到通道。然后close()通道,就可以了。这样的话,你在go execute中创建的go func中select就会自动通过,自动的kill进程了(一个go func对应一个python,自己kill进程,而且go func也退出了,不仅python退出了,go func也退出了,两全齐美)。可能描述的不清楚。等开会的时候,可以探讨一下。

from lmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.