1

one question: I want to run two different exe files parallel (Windows). All my tests starts the two applications, but one after the other (after closing the application). What's wrong?

import threading
import subprocess
import os.path

def Worker(aPrg):
    _, name = os.path.split(aPrg)
    if os.path.isfile(aPrg):
        lExe = []
        lExe.append(aPrg)
        print('Start: ' + name)
        lResult = subprocess.call(lExe)
    else:
        print('ERROR: ' + name + ' not available!')
    return

def main():
    t1 = threading.Thread(target=Worker('C:\\windows\\notepad.exe'))
    t2 = threading.Thread(target=Worker('c:\\windows\\explorer.exe'))
    t1.start()
    t2.start()

if __name__ == '__main__':
        main()

Thanks for all ideas!

Geosucher

Geosucher
  • 107
  • 1
  • 5

1 Answers1

0

The reasons for this problem is discussed here : Python threading appears to run threads sequentially

This should help you:

import subprocess
import os.path
import multiprocessing

def Worker(aPrg):
    _, name = os.path.split(aPrg)
    if os.path.isfile(aPrg):
        lExe = []
        lExe.append(aPrg)
        print('Start: ' + name)
        lResult = subprocess.call(lExe)
    else:
        print('ERROR: ' + name + ' not available!')
    return

def main():
    p = multiprocessing.Pool(2)
    p.map(Worker, ('c:\\windows\\explorer.exe','c:\\windows\\explorer.exe'))

if __name__ == '__main__':
        main()
Community
  • 1
  • 1
ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17