Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6614931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:23:56+00:00 2026-05-25T20:23:56+00:00

I have a program, P1 , which I need to run about 24*20000 times

  • 0

I have a program, P1, which I need to run about 24*20000 times with different inputs. The problem is the P1 hangs and I should force it to quite manually (kill). My first solution was writing a python script to call P1 and passing the proper input and receiving the output using popen and communicate. But due to the nature of communicate which waits for the output, I can not kill the process as long as it is waiting for the response. I am on Windows.

I tried to use multiprocess function, but it only runs the P1 and failed in sending the input to it. I am suspicious about not using pipes in popen and tried a little bit but I guess I can’t receive the output from P1.

Any ideas?

# This code run XLE and pass the intended input to it automatically
 def startExe(programPath, programArgStr):
 p = subprocess.Popen(programPath,stdout=subprocess.PIPE,stdin=subprocess.PIPE) p.stdin.write(programArgStr)
 p.communicate()[0]
# Need to kill the process if it takes longer than it should here

def main(folder): 
.. 
#loop
programArgStr = "create-parser"+path1+";cd "+ path2+"/s"+ command(counter) +";exit"

startExe(path, programArgStr)
..

As you can see if P1 can finish the given task successfully it can exit itself, using the exit commands passed to it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:23:56+00:00Added an answer on May 25, 2026 at 8:23 pm

    I solved my problem by editing current code and putting the killer code in a separate file.
    to do that I add a line to write PID of the newly created process in a file.

        #//Should come before p.commiunicate
        WriteStatus(str(p.pid) + "***" + str(gmtime().tm_hour) + "***" + str(gmtime().tm_min))        
        p.communicate()[0]
    

    And the process monitor executed seperately and checks every 2 mins to see if the processes listed in the file are still active. If yes kill them and remove their ID.

     def KillProcess(pid):
    
        subprocess.Popen("TASKKILL /PID "+ str(pid) + " /F /T" , shell=True)
        subprocess.Popen("TASKKILL /im WerFault.exe /F /T" , shell=True)
        print "kill"
    
        def ReadStatus(filePath):
        print "Checking" + filePath
        try:
                status = open(mainPath+filePath, 'r').readline()
        except:
                print "file removed" + filePath
                return 0
        if len(status) >0:
                info = status.split("***")                
                time = [gmtime().tm_hour, gmtime().tm_min]
                print time
    
                # Time deifferences
                difHour = time[0]- int(info[1])
                if difHour == 0: # in the same hour
                        difMin =  time[1]- int(info[2])
                else:
                        difMin = 60 - int(info[2]) + time[1]
                if difMin > 2:
                        try:
                                open(mainPath+filePath, 'w').write("")
                                KillProcess(info[0])
                        except:
                                pass
        return 1
    
      def monitor():
        # Read all the files
        listFiles = os.listdir(mainPath)
        while len(listFiles)>0:
                #GO and check the contents
                for file in listFiles:
                        #Open the file and Calculate if the process should be killed or not
                        pid = ReadStatus(file)
                        #Update listFiles due to remove of file after finishing the process '
                        # of each folder is done
                        listFiles = os.listdir(mainPath)
                for i in range(0,4):
                        time.sleep(30) #waits 30 sec
                        subprocess.Popen("TASKKILL /im WerFault.exe /F /T" , shell=True)
        #to indicate the job is done
        return 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to gain some run-time information about a C++ program, which is kinda
I have a program in which I need to store a Class object into
Just a quick question here. I have a program in which I need to
I have a program which I would like to run every X min the
We have some COBOL programs in our financial applications which need to interact with
I have a LAMP (PHP) web app which need to interface with programs on
I have a program which needs to behave slightly differently on Tiger than on
I have a program which deliberately performs a divide by zero (and stores the
I have a program which has some Textareas / Labels these can be anywhere
I have a program which needs installing on windows 64 boxes. Most of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.