Python Forum
Using Subprocess.Popen to start another python script running in background on Window
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Subprocess.Popen to start another python script running in background on Window
#1
Hi,
New to Python but loving it. I am trying to run another python script using subprocess.Popen and have it run in the background. It works ok if I run it from the command line, however if I run it using our batch scheduling solution which is BMC Control-M the scripts starts but does not finish as it seems to be waiting for the child process to finish. If I kill the python running process the job completes successfully.

Any help appreciated.

Regards
Brian

import subprocess

def startlogging():
  DETACHED_PROCESS=0x0000008
 
  pid = subprocess.Popen(["python", "scriptname.py"], creationflags=DETACHED_PROCESS).pid

  pidid = str(pid)

  with open(Tr_Fj_Params.pid_file, "w") as f:
     wtrite_data = f.write(pidid)
     f.close()

if __name__ =='__main__':
  startlogging()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  No Internet connection when running a Python script basil_555 8 597 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 481 Mar-10-2024, 07:24 PM
Last Post: Winfried
Information subprocess.Popen() suddenly giving me grief? davecotter 3 617 Dec-13-2023, 10:49 PM
Last Post: davecotter
  Help Running Python Script in Mac OS emojistickers 0 345 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 671 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,768 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  Starting and running .bat in background, tkinter in foreground ProfMeowintgon 9 1,499 Sep-01-2023, 12:00 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,245 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python script running under windows over nssm.exe JaroslavZ 0 711 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Running script with subprocess in another directory paul18fr 1 3,752 Jan-20-2023, 02:33 PM
Last Post: paul18fr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020