process and spinning slash

benz benzwt at yahoo.com.tw
Sun Oct 30 11:45:31 EST 2005


I am trying to fork and exec a child by python. Additionally, I am
attempting
to have a spinning slash while the child is running.

My code is as below:

import sys, os, time


def spin(delay):

  pattern=['-','\\','|','/','-','\\','|']

  while 1:
    for i in pattern:
      sys.stdout.write(i + " ")
      sys.stdout.flush()
      sys.stdout.write("\b\b")
      time.sleep(delay)

pid = os.fork()

if pid == 0:
  os.execvp("du",("du","-shc","/"))
else:
  spin(0.05)


However, the spinner is kept spinning even the child process was ended.
Any idea ? Thanks!




More information about the Python-list mailing list