This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author alanwilter
Recipients alanwilter
Date 2010-08-04.08:33:53
SpamBayes Score 9.0005225e-12
Marked as misclassified No
Message-id <1280910836.88.0.645209486589.issue9504@psf.upfronthosting.co.za>
In-reply-to
Content
I have this example code to illustrate a problem I am having with python3. It works fine with python 2.6 and 2.7 but does not with python 3.1.

from __future__ import print_function
import os, subprocess, signal

def signal_handler( signum, frame ):

    print( "PID: %s" % pid )
    print( "Timed out! Process %s killed, max exec time (%ss) exceeded" % (pid, timeTol ) )
    os.kill( int( pid ), 15 )
    raise Exception( "Taking too long to finish... aborting!" )

if __name__ == '__main__':

    timeTol = 5

    cmd = 'find /'

    signal.signal(signal.SIGALRM, signal_handler)
    signal.alarm(timeTol)

    p = subprocess.Popen(cmd, shell=True, stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
    pid = p.pid

    out = str( p.communicate()[0].decode() )
    print(out)


Executing it:

time python3.1 timout.py
PID: 27687
Timed out! Process 27687 killed, max exec time (5s) exceeded
Traceback (most recent call last):
  File "timout.py", line 23, in <module>
    out = str( p.communicate()[0].decode() )
  File "/sw/lib/python3.1/subprocess.py", line 719, in communicate
    stdout = self.stdout.read()
  File "timout.py", line 9, in signal_handler
    raise Exception( "Taking too long to finish... aborting!" )
Exception: Taking too long to finish... aborting!
python3.1 timout.py  0.52s user 3.88s system 19% cpu 22.841 total

#### It prints essentially the same thing with a *very* *big* difference it takes 22 seconds and actually the alarm only works when the whole task ('find /') is finished.
History
Date User Action Args
2010-08-04 08:33:57alanwiltersetrecipients: + alanwilter
2010-08-04 08:33:56alanwiltersetmessageid: <1280910836.88.0.645209486589.issue9504@psf.upfronthosting.co.za>
2010-08-04 08:33:55alanwilterlinkissue9504 messages
2010-08-04 08:33:53alanwiltercreate