Skip to content

Instantly share code, notes, and snippets.

@AlexDemian
Created July 9, 2018 13:06
Show Gist options
  • Save AlexDemian/6ef7f0e55e1f553b10df3258b2583dba to your computer and use it in GitHub Desktop.
Save AlexDemian/6ef7f0e55e1f553b10df3258b2583dba to your computer and use it in GitHub Desktop.

Revisions

  1. AlexDemian created this gist Jul 9, 2018.
    22 changes: 22 additions & 0 deletions parent.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import subprocess
    import os
    import signal
    import time

    path = os.path.abspath(__file__).rpartition('/')[0]

    child_comm = ['python %s/child.py' % path]
    parent_comm = ['python %s/parent.py' % path]

    proc = subprocess.Popen(child_comm, shell=True)
    print 'New child process created'

    your_condition = True

    while your_condition:
    time.sleep(1)

    subprocess.Popen(parent_comm, shell=True, preexec_fn=os.setpgrp)
    print 'New wrapper(parent process) created'
    print 'Terminating old processgroup...'
    os.killpg(os.getpgid(proc.pid), signal.SIGTERM)