please, help with python 3.1

Alan alanwilter at gmail.com
Tue Aug 3 08:35:30 CEST 2010


Hello List,

Please, can someone at least try this code below in python 3 and report me
back whether it works or not? Because for me this code works in python 2.6
but not with python 3.1. Thanks!


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)


Alan

-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100803/5ec314c2/attachment.html>


More information about the Python-list mailing list