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

Blocking readline() Call?

Hi, everyone,

I'm just figuring Python out but have become stalled with the following
snippit of code: For some reason, the program stalls after the "read line:
x" for the last line. The 'done reading cycle map' message is never
generated:

while 1:
line = file.readline()
if line == '':
continue
data = line.strip().split(':')
cycleMap[int(data[0])] = int(data[1])
i = i + 1
print ('read line %d' % i)
file.close()
print ('done reading cycle map')

I thought readline() was supposed to be non-blocking. Have I misunderstood
something?

Thanks,
Scott
--
Remove ".nospam" from the user ID in my e-mail to reply via e-mail.
Jul 18 '05 #1
5 3363
Scott Brady Drummonds wrote:

I'm just figuring Python out but have become stalled with the following
snippit of code: For some reason, the program stalls after the "read line:
x" for the last line. The 'done reading cycle map' message is never
generated:

while 1:
line = file.readline()
if line == '':
continue
Correct this: you want "break", not continue.
data = line.strip().split(':')
cycleMap[int(data[0])] = int(data[1])
i = i + 1
print ('read line %d' % i)
file.close()
print ('done reading cycle map')

I thought readline() was supposed to be non-blocking. Have I misunderstood
something?


Yes, the problem wasn't where you thought it was. A well-placed print
statement or two would have showed you that readline was being called
repeatedly, not blocking.

-Peter
Jul 18 '05 #2
On Mon, Nov 10, 2003 at 11:59:42AM -0800, Scott Brady Drummonds wrote:
Hi, everyone,

I'm just figuring Python out but have become stalled with the following
snippit of code: For some reason, the program stalls after the "read line:
x" for the last line. The 'done reading cycle map' message is never
generated:

while 1:
line = file.readline()
if line == '':
continue
I think you mean "break" here, not "continue".

data = line.strip().split(':')
cycleMap[int(data[0])] = int(data[1])
i = i + 1
print ('read line %d' % i)
file.close()
print ('done reading cycle map')

Another way to write this loop would be:

for line in file:
...

Jp

Jul 18 '05 #3

"Scott Brady Drummonds" <sc**********************@intel.com> wrote in
message news:bo**********@news01.intel.com...
Hi, everyone,

I'm just figuring Python out but have become stalled with the following
snippit of code: [code deleted]

JP said: I think you mean "break" here, not "continue".
Peter said: Correct this: you want "break", not continue
Mel said: 'continue' doesn't mean what you think it means. Try 'break'.


So, what is it that you people are trying to tell me? Please don't beat
around the bush.

Scott

P.S. Sarcasm aside, thanks to all three of you for pointing out my very
basic mistake. :)
Jul 18 '05 #4
"Scott Brady Drummonds" <sc**********************@intel.com> wrote in message news:<bo**********@news01.intel.com>...
Hi, everyone,

I'm just figuring Python out but have become stalled with the following
snippit of code: For some reason, the program stalls after the "read line:
x" for the last line. The 'done reading cycle map' message is never
generated:

while 1:
line = file.readline()
if line == '':
continue
Perhaps you meant break.
data = line.strip().split(':')
cycleMap[int(data[0])] = int(data[1])
i = i + 1
print ('read line %d' % i)
file.close()
print ('done reading cycle map')

I thought readline() was supposed to be non-blocking. Have I misunderstood
something?

Thanks,
Scott


Regards, Paul Clinch
Jul 18 '05 #5
Scott Brady Drummonds wrote:

"Scott Brady Drummonds" <sc**********************@intel.com> wrote in
message news:bo**********@news01.intel.com...
Hi, everyone,

I'm just figuring Python out but have become stalled with the following
snippit of code:

[code deleted]

JP said:
I think you mean "break" here, not "continue".


Peter said:
Correct this: you want "break", not continue


Mel said:
'continue' doesn't mean what you think it means. Try 'break'.


So, what is it that you people are trying to tell me? Please don't beat
around the bush.


Sorry we were unclear, Scott. See Paul Clinch's post for an answer that
is more concise and perhaps easier for you to understand. ;-) ;-)

-Peter
Jul 18 '05 #6

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

Similar topics

2
by: J. Xu | last post by:
I am a newbie to python. I am writing a client application, I need to read query results from the server. Mostly I'll have a file object for the connection to the server. So I use read() or...
2
by: Uwe Mayer | last post by:
Hi, I am looking for a way to make the call to a file objects readline() method blocking when there is no more data, until data is appended to the file, similar to the way $ tail -F <system...
3
by: Uwe Mayer | last post by:
Hi, I want two python programs to communicate over stdIO channels. The one executes the other via the popen3 function: amc = Popen3("./amc/amc.py", True, 0) line = stdin.readline()...
4
by: Marc Carter | last post by:
I am trying to rewrite a PERL automation which started a "monitoring" application on many machines, via RSH, and then multiplexed their collective outputs to stdout. In production there are lots...
1
by: Guy Korland | last post by:
Hi, 1. How can I read stream in blocking mode? Meaning stop the thread till it get a new line sign? Or getting an event from the stream on new income data? 2. How can I convert 2 bytes to...
2
by: Richard Bell | last post by:
Is there a way to do a non-blocking console read in VB.net? Something a bit like the old INKEY$?
6
by: placid | last post by:
Hi all, I have been looking into non-blocking read (readline) operations on PIPES on windows XP and there seems to be no way of doing this. Ive read that you could use a Thread to read from the...
3
by: Tom Plunket | last post by:
I'm using subprocess to launch, well, sub-processes, but now I'm stumbling due to blocking I/O. Is there a way for me to know that there's data on a pipe, and possibly how much data is there so...
3
by: nrworld | last post by:
Hi, In my app, I am registering an event with WMI, and to make it wait for the event, I'm using Console.ReadLine() for blocking. But it seems that when I use the same code as Service,...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.