Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > thread hangs when using subprocess only in specific circumstances

Reply
Thread Tools

thread hangs when using subprocess only in specific circumstances

 
 
Toon Verstraelen
Guest
Posts: n/a
 
      01-09-2006
Hi,

I recently had a thread problem and I could reduce it to a very short
example that shows the problem. I hope it has its origin in my
misunderstanding of how python threads work. Here it is:

--- my_thread.py ---

import threading
from subprocess import Popen, PIPE, STDOUT

class MyThread(threading.Thread):
def run(self):
print "before Popen"
sp = Popen(["ls", "-al"], stdout=PIPE, stderr=STDOUT)
print "before first line"
for line in sp.stdout:
print line[:-1]
print "after last line"


t = MyThread()
t.start()

--- main.py ---

import my_thread


----------------

If I start my_thread.py directly there is no problem, but when i run
'python main.py' the thread hangs on the creation of the Popen object. I'm
using python 2.4.2 on gentoo linux. Can someone reproduce the problem?

Thanks for reading this.

Toon
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      01-10-2006
On Mon, 09 Jan 2006 22:59:45 +0100, Toon Verstraelen
<(E-Mail Removed)> declaimed the following in comp.lang.python:

> --- main.py ---
>
> import my_thread
>

Are you sure it is hanging? I'd expect this to do the import
(starting the thread in the import context) and then to immediately exit
since there is no code in the main thread to wait for anything.
--
> ================================================== ============ <
> http://www.velocityreviews.com/forums/(E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      01-10-2006
In article <(E-Mail Removed)>,
Dennis Lee Bieber <(E-Mail Removed)> wrote:

> On Mon, 09 Jan 2006 22:59:45 +0100, Toon Verstraelen
> <(E-Mail Removed)> declaimed the following in comp.lang.python:
>
> > --- main.py ---
> >
> > import my_thread
> >

> Are you sure it is hanging? I'd expect this to do the import
> (starting the thread in the import context) and then to immediately exit
> since there is no code in the main thread to wait for anything.


But this would also be true when he runs the module directly,
right?

I don't know about that, but when I run it via import, instead
of hanging on NetBSD 2.0 it crashes, and you get the file and
line number of the pthread function where it died. Shortly
after doing a yield that's apparently expected to always work.

If not via import, no problem. If not subprocess, no problem
(I can use os.popen, or os.pipe/fork/execve, etc.) I imagine
this is related to the problem on Linux.

Donn Cave, (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In which circumstances a Class.forName() can fail? Ivo Java 7 06-04-2009 06:36 PM
Under what circumstances will this use of strncpy fail? Ron C Programming 9 03-10-2007 01:11 AM
Webcontrols are NULL under certain circumstances in User Controls kens@180solutions.com ASP .Net 2 01-03-2006 05:03 PM
Under what circumstances can the STL move a vector? Richard Thompson C++ 11 02-06-2005 06:41 PM
Clear hangs up - & hangs up - & hangs up Sue Bilstein NZ Computing 26 03-07-2004 01:33 AM



Advertisments