How to kill a process (via dialog box) while waiting?
#1
I tried something like this:

Code:
pDialog = xbmcgui.DialogProgress()
pDialog.create('XBMC', 'Press Cancel to Exit')
Progmain = subprocess.Popen(<Program & Parameters>)
Progmain.wait()
   if (pDialog.iscanceled()):
      os.kill(Progmain)


Obviously that didnt work. I want the running program to terminate when I hit cancel, can anyone help?
Reply
#2
os.kill do not work because this function do only operate on pid and signals.
I guess sys.exit is may better
Reply
#3
Or try: sys.modules.clear()
Reply
#4
Well my code obviously can't work because it waits for the program to close before checking the dialog box. Any more ideas?
Reply
#5
RandomXBMCUser Wrote:Well my code obviously can't work because it waits for the program to close before checking the dialog box. Any more ideas?

I guess you could determine the state of the process inside the loop.

Code:
#########################################################
# Function  : OSRun                                     #
#########################################################
# Parameter :                                           #
#                                                       #
# command     command to execute over ssh               #
# backg       boolean :                                 #
#             - true  command is put into background &  #
#             - false command is not startet in         #
#               background (very dangerous .... )       #
# busys       boolean :                                 #
#             - show busy-dialog during the operation   #
#                                                       #
# Returns   :                                           #
#                                                       #
#             rc-val from os.system call                #
#                                                       #
#########################################################
def OSRun(command,backg,busys):

    global __configLinux__
    global __verbose__

    if (busys):
        xbmc.executebuiltin("ActivateWindow(busydialog)")
    sys.platform.startswith('linux')


    sshlog ="echo \"" + command + "\" >> " + __configLinux__[38]
    status = os.system("%s" % (sshlog))

    if (__verbose__ == 'true'):
        OSlog("Command to log inside ssh:" + sshlog)
        OSlog ("OSRun start")


    commandssh = "ssh " + __configLinux__[6] + " " + __configLinux__[40] + command + " "

    if (backg):
        commandssh = commandssh + " > /dev/null 2>&1 &"

    status = os.system("%s" % (command))

    if (__verbose__ == 'true'):
        OSlog("Command to run :" + commandssh)

    # No we execute the command  ...
    # over ssh

    status = os.system("%s" % (commandssh))

    if (busys):
        xbmc.executebuiltin("Dialog.Close(busydialog)")

    if (__verbose__ == 'true'):
        OSlog ("OSRun end")

    return status

#########################################################
Reply
#6
I tried this code:

Code:
aDialog = xbmcgui.DialogProgress()
  aDialog.create('XBMC', 'Press Cancel to Stop Program...')
  myProg = subprocess.Popen(<Program Parameters>)
  progcheck = 0
  while progcheck == 0:
      time.sleep(2)
      retcode = myProg.Poll()
      if (aDialog.iscanceled()):
        sys.close(myProg)
        progcheck = 1
      if retcode:
        progcheck = 1

But the dialog box instantly closes when the polling of the program starts. Any suggestions?
Reply
#7
Eek
Reply
#8
I'm working on the Windows platform, btw.
Reply
#9
One last plea for someone to let me know whats wrong with my code...last bump, I promise!

Quote:But the dialog box instantly closes when the polling of the program starts. Any suggestions?

Code:
aDialog = xbmcgui.DialogProgress()
  aDialog.create('XBMC', 'Press Cancel to Stop Program...')
  myProg = subprocess.Popen(<Program Parameters>)
  progcheck = 0
  while progcheck == 0:
     time.sleep(2)
     retcode = myProg.poll()
     if (aDialog.iscanceled()):
       sys.close(myProg)
       progcheck = 1
     if retcode:
       progcheck = 1
Reply

Logout Mark Read Team Forum Stats Members Help
How to kill a process (via dialog box) while waiting?0