Re: process and spinning slash
- From: aleaxit@xxxxxxxxx (Alex Martelli)
- Date: Sun, 30 Oct 2005 09:03:52 -0700
benz <benzwt@xxxxxxxxxxxx> 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
.
- Follow-Ups:
- Re: process and spinning slash
- From: Fredrik Lundh
- Re: process and spinning slash
- References:
- process and spinning slash
- From: benz
- process and spinning slash
- Prev by Date: Re: Automatic binding of **kwargs to variables
- Next by Date: Re: process and spinning slash
- Previous by thread: process and spinning slash
- Next by thread: Re: process and spinning slash
- Index(es):
Relevant Pages
|