Re: please, help with python 3.1

2010-08-03 Thread Antoine Pitrou
On Tue, 3 Aug 2010 10:28:49 +0100
Alan Wilter Sousa da Silva  wrote:
> Now with python3.1:
> 
> 
> 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 
> 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.

This seems to be a bug. Can you report it at http://bugs.python.org ?

Thanks

Antoine.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread Alan Wilter Sousa da Silva
Ok:

Here goes the code again and results:

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)



time python2.6 timout.py
PID: 27644
Timed out! Process 27644 killed, max exec time (5s) exceeded
Traceback (most recent call last):
  File "timout.py", line 23, in 
out = str( p.communicate()[0].decode() )
  File "/sw/lib/python2.6/subprocess.py", line 693, 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!
python2.6 timout.py  0.10s user 0.47s system 11% cpu 5.113 total

 WORKED as expected 


Now with python3.1:


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 
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.


I hope it's better now.

Thanks,

Alan

On Tue, Aug 3, 2010 at 08:42, rantingrick  wrote:

> On Aug 3, 2:28 am, Chris Rebert  wrote:
> > -- Forwarded message --
> > From: Alan 
> > Date: Tue, Aug 3, 2010 at 12:25 AM
> > Subject: Re: please, help with python 3.1
> > To: Chris Rebert 
> >
> > Sorry,
> > I will explain.
>
> Well it looks like he forgot to post the traceback!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
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<<
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread Steven D'Aprano
Hello Alan,


I'm sorry, I can't see the code you say you posted. I can't see ANY of 
your posts, only the replies from Chris Rebert. 

Are you using Google Groups to post? If so, many people here will have 
difficulty seeing your posts, as Google Groups is notorious for allowing 
spammers, and in self-defence many mailing lists and newsgroups just 
ignore anything from Google Groups.

Looking at the message Chris forwarded:

  [quote]
  I am using for a task 'find /' expecting this to last longer, usually
  much longer than 5 sec. If you run the code I sent in python 2.6, it
  will stop after 5 sec and print messages. If you run the same code in
  python3 (and if your task last more than 5 sec as expected, otherwise
  replace "cmd = 'find /'" with something suitable), python3 alarm
  doesn't work and the job is not stopped after 5 sec, taking minutes to
  finish.
  [end quote]


I'm sorry, but I can't make heads or tails of that. At the very least, 
you need to explain what code you are using, and what the problem is. 
What do you mean "python3 alarm doesn't work"? What alarm? What do you 
mean it doesn't work? Just saying "it doesn't work" is pointless.

Is the problem that your code runs in seconds under Python 2.6 and takes 
minutes under Python 3.1? Are you sure you are using 3.1 and not 3.0? 3.0 
is VERY slow and should be avoided.

We may need to see your code, and some sample data, in order to have any 
hope of helping you.



Regards,


Steven.


On Tue, 03 Aug 2010 00:28:04 -0700, Chris Rebert wrote:

> -- Forwarded message ---------- From: Alan
> 
> Date: Tue, Aug 3, 2010 at 12:25 AM
> Subject: Re: please, help with python 3.1 To: Chris Rebert
> 
> 
> Sorry,
> I will explain. I am using for a task 'find /' expecting this to last
> longer, usually much longer than 5 sec. If you run the code I sent in
> python 2.6, it will stop after 5 sec and print messages.
> If you run the same code in python3 (and if your task last more than 5
> sec as expected, otherwise replace "cmd = 'find /'" with something
> suitable), python3 alarm doesn't work and the job is not stopped after 5
> sec, taking minutes to finish.
> I hope it may help you to help me.
> Thanks,
> Alan
> 
> On Tue, Aug 3, 2010 at 08:11, Chris Rebert  wrote:
>>
>> On Mon, Aug 2, 2010 at 11:35 PM, Alan  wrote:
>> > 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!
>>
>> Please specify *in exactly what way* the code is not working. Is an
>> exception being thrown? Then include the full traceback. Is the
>> behavior not what you expected/intended? Then say what it's doing vs.
>> what you want it to do.
>>
>> Cheers,
>> Chris
>> --
>> Getting Debugging Help 101: Don't just say "there's a problem". Say
>> what the problem is.
>> http://blog.rebertia.com



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread rantingrick
On Aug 3, 2:28 am, Chris Rebert  wrote:
> -- Forwarded message --
> From: Alan 
> Date: Tue, Aug 3, 2010 at 12:25 AM
> Subject: Re: please, help with python 3.1
> To: Chris Rebert 
>
> Sorry,
> I will explain.

Well it looks like he forgot to post the traceback!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread Chris Rebert
-- Forwarded message --
From: Alan 
Date: Tue, Aug 3, 2010 at 12:25 AM
Subject: Re: please, help with python 3.1
To: Chris Rebert 

Sorry,
I will explain. I am using for a task 'find /' expecting this to last
longer, usually much longer than 5 sec.
If you run the code I sent in python 2.6, it will stop after 5 sec and
print messages.
If you run the same code in python3 (and if your task last more than 5
sec as expected, otherwise replace "cmd = 'find /'" with something
suitable), python3 alarm doesn't work and the job is not stopped after
5 sec, taking minutes to finish.
I hope it may help you to help me.
Thanks,
Alan

On Tue, Aug 3, 2010 at 08:11, Chris Rebert  wrote:
>
> On Mon, Aug 2, 2010 at 11:35 PM, Alan  wrote:
> > 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!
>
> Please specify *in exactly what way* the code is not working.
> Is an exception being thrown? Then include the full traceback.
> Is the behavior not what you expected/intended? Then say what it's
> doing vs. what you want it to do.
>
> Cheers,
> Chris
> --
> Getting Debugging Help 101: Don't just say "there's a problem". Say
> what the problem is.
> http://blog.rebertia.com



--
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<<
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread rantingrick
On Aug 3, 2:11 am, Chris Rebert  wrote:
> On Mon, Aug 2, 2010 at 11:35 PM, Alan  wrote:
> > 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!


Oh my Gawd! Python3x is not backwards compatible! 8^O

You know it would be nice if you "esteemed" Pythonista's would send
out a newsletter or something before making changes that could break
code. We are trying to maintain a code base out here you know. Geez!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please, help with python 3.1

2010-08-03 Thread Chris Rebert
On Mon, Aug 2, 2010 at 11:35 PM, Alan  wrote:
> 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!

Please specify *in exactly what way* the code is not working.
Is an exception being thrown? Then include the full traceback.
Is the behavior not what you expected/intended? Then say what it's
doing vs. what you want it to do.

Cheers,
Chris
--
Getting Debugging Help 101: Don't just say "there's a problem". Say
what the problem is.
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


please, help with python 3.1

2010-08-02 Thread Alan
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<<
-- 
http://mail.python.org/mailman/listinfo/python-list