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
  Running script from remote to server invisiblemind 4 742 Mar-28-2025, 07:57 AM
Last Post: buran
  Detect if another copy of a script is running from within the script gw1500se 4 1,133 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  Asyncio subprocess blocking with python workload only lloydbond 1 807 Dec-20-2024, 05:14 PM
Last Post: lloydbond
  Cant get powershell script to run with subprocess robertkwild 2 1,444 Jun-27-2024, 01:23 PM
Last Post: robertkwild
  Understanding subprocess.Popen Pedroski55 6 2,062 May-12-2024, 10:46 AM
Last Post: Pedroski55
  No Internet connection when running a Python script basil_555 8 3,305 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 6,651 Mar-10-2024, 07:24 PM
Last Post: Winfried
Information subprocess.Popen() suddenly giving me grief? davecotter 3 1,816 Dec-13-2023, 10:49 PM
Last Post: davecotter
  Help Running Python Script in Mac OS emojistickers 0 956 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 1,768 Nov-01-2023, 03:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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