Re: process and spinning slash



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
.



Relevant Pages

  • Re: using wait within while loop
    ... while [wait $PID] ... The specified process wasn't an immediate child or had already been ... The while loop will terminate straight away. ...
    (comp.unix.shell)
  • Re: problem with rand on OSX
    ... Each child has a different $slp on my system. ... because the children explicitly break out of the loop with $pid set to ... $pid is used in a loop in the parent, but at the end of the loop, it's ...
    (comp.lang.perl.misc)
  • Re: Forking problem
    ... I've the following bit of code in a scripts: ... and the loop goes round indefinitely. ... As far as I can see, this shouldn't happen - if the fork fails, pid ... If the program aborts with no forensic trace, ...
    (comp.lang.perl.misc)
  • Re: Forking problem
    ... I've the following bit of code in a scripts: ... and the loop goes round indefinitely. ... As far as I can see, this shouldn't happen - if the fork fails, pid ... If the program aborts with no forensic trace, ...
    (comp.lang.perl.misc)
  • Re: Problems with SCO 5.0.6 and Informix 7.12 (long)
    ... > %CPU PID PPID USER COMMAND ... yes, the program is stuck in an infinite CPU loop, ... interrupted only by its own self-monitoring alarm chain. ...
    (comp.unix.sco.misc)