FAQ
Hi there,

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.

Please, can someone tell me why or how to fix this example?


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)


Many thanks,

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100802/c32a4115/attachment.html>

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 2, '10 at 10:37a
activeAug 2, '10 at 10:37a
posts1
users1
websitepython.org

1 user in discussion

Alan: 1 post

People

Translate

site design / logo © 2022 Grokbase