473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

thread hangs when using subprocess only in specific circumstances

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
Jan 9 '06 #1
1 1911
In article <qg********************************@4ax.com>,
Dennis Lee Bieber <wl*****@ix.netcom.com> wrote:
On Mon, 09 Jan 2006 22:59:45 +0100, Toon Verstraelen
<To**************@UGent.be> 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, do**@u.washington.edu
Jan 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon Wright | last post by:
Trying to work around the lack of pexpect for native windows python I had a play with os.popen2 and some threads. This looks promising enough for what I want to do, but I hit on a problem with...
0
by: Michael Hobbs | last post by:
I just wanted to see if anyone else experienced a problem with the Thread.join() method in Python 2.4. Unfortunately, I did not debug this problem fully before re-writing my code to avoid...
1
by: Serge | last post by:
Hi, I am having some lock up problems in my c# code. when from a 2nd thread (worker thread) i call a normal standard function like Trace.WriteLine the 2nd thread freezes/hangs. The 2nd thread...
6
by: Brian Gideon | last post by:
How have you handled the finalization of thread-specific unmanaged resources? My question pertains specifically to using the DDEML which is a thread-specific API. In other words, every call to...
6
by: gregpinero | last post by:
Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() while 1: pass And I want to call it from another Python process and read the value 'hi'. How...
5
by: Eric Promislow | last post by:
Here's a small Python program I use to grab the output from rake: ===== from subprocess import Popen, PIPE p = Popen(args='c:\\ruby\\bin\\ruby.exe c:\\ruby\\bin\\rake -T',...
10
by: sophie_newbie | last post by:
Hi, I'm trying to write a piece of code that spawns a thread and prints dots every half second until the thread spawned is finished. Code is something like this: import threading class...
0
by: Kenneth McDonald | last post by:
When making calls of the form Popen(cmd, shell=True, stdout=subprocess.PIPE), we've been getting occasional, predictable hangs. Will Popen accumulate a certain amount of stdout and then block...
0
by: Christian Heimes | last post by:
Kenneth McDonald wrote: The subprocess module has already an API method for your use case. The communicate() method of a subprocess.Popen instance takes an optional stdin string and returns the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.