Re: process and spinning slash
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: process and spinning slash

From: Alex Martelli <aleaxit@yahoo.com>
Date: Sun Oct 30 2005 - 17:03:52 CET

benz <benzwt@yahoo.com.tw> wrote:
   ...
> 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.

It would be astonishing if it were otherwise! The loop in function spin
is deliberately coded to NEVER terminate, so of course it never does.

> Any idea ? Thanks!

Have the spin function accept the pid argument and exit the loop if said
pid has terminated; to check the latter, e.g., os.kill(pid, 0) -- this
will raise an OSError if no process with that pid exists, so you can use
a try/except OSError: to catch that and break as appropriate.

Alex
Received on Mon Nov 21 01:06:03 2005