473,401 Members | 2,139 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,401 software developers and data experts.

the pipe reading in Thread dose not work.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import string, sys
from threading import Thread
import os
import time

class test_pipe(Thread):
def __init__(self, fd):
Thread.__init__(self)
self.testfd = fd

def run(self):
print "started thread begin -----"
while True:
buf = self.testfd.read()
print "receive %s" % (buf)
time.sleep(1)
#print "hoho"

if __name__ == "__main__":

stdin_r, stdin_w = os.pipe()
#stdout_r, stdout_w = pipe()

f_w = os.fdopen(stdin_w, "w", 0)

thrd = test_pipe(os.fdopen(stdin_r, "r", 0))
thrd.start()

time.sleep(1)

while True:
f_w.write("help\r\n")
time.sleep(1)

thrd.join()
--------------------------------------------
well, I want the following small test about pipe() in thread().
OK, I write to the pipe in the main thread, and I created a new thread
for reading from the pipe, then it will print what it received from
the pipe().

But, it seems it block at the "self.testfd.read()".

So, is there and suggestion and explaination about it?

Thanks in advance.
Jun 1 '08 #1
0 1121

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

Similar topics

5
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read...
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: funtoosh | last post by:
Hi Scenario: I have a shell script e.g. a.bash This script wraps a program called "generate" like this: generate > /tmp/y.txt 2>&1 # both stdout and stderr r redirected to y.txt
5
by: Mike Goatly | last post by:
Hi, I need to be able to read the amount of processor time a thread has taken up. So far I've found the following methods open to me: 1) Find the relevant ProcessThread in the current...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
8
by: Rohit Kumbhar | last post by:
Hi, I am writing a Windows Forms C# application for reading files on the disk. My problem is the UI freezes when restored after being minimized for a long time . I have a separate thread...
4
by: Shark | last post by:
Hi, I need a help. My application reads data from COM port, this data is then parsed and displyed on: 1. two plotters 2. text box. I'm using Invoke method to update UI when new data is...
0
by: Leon zhang | last post by:
#!/usr/bin/env python # -*- coding: utf-8 -*- import string, sys from threading import Thread import os import time class test_pipe(Thread): def __init__(self, fd):
0
by: Jean-Paul Calderone | last post by:
On Sun, 1 Jun 2008 07:32:39 -0700 (PDT), Leon zhang <leoncamel@gmail.comwrote: file.read() reads the entire contents of the file. Your code never closes the write end of the pipe, so the read...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.