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.00052e-12
Marked as misclassified No
Message-id <>
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)

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

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

Executing it:

time python3.1
PID: 27687
Timed out! Process 27687 killed, max exec time (5s) exceeded
Traceback (most recent call last):
  File "", line 23, in <module>
    out = str( p.communicate()[0].decode() )
  File "/sw/lib/python3.1/", line 719, in communicate
    stdout =
  File "", line 9, in signal_handler
    raise Exception( "Taking too long to finish... aborting!" )
Exception: Taking too long to finish... aborting!
python3.1  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.
Date User Action Args
2010-08-04 08:33:57alanwiltersetrecipients: + alanwilter
2010-08-04 08:33:56alanwiltersetmessageid: <>
2010-08-04 08:33:55alanwilterlinkissue9504 messages
2010-08-04 08:33:53alanwiltercreate