![](/img/trans.png)
[英]How to only read first none empty line in python using sys.stdin
[英]How to get first N lines from sys.stdin line by line on Python
我在為MapReduce編寫減速器時遇到了一個問題。 我想獲得前10行非常大的文件,我用於循環和中斷。 但是,break命令在hadoop上發出錯誤,所以我正在尋找另一種方法:
for line in fileinput.input():
if(counter>limit):
break
line = line.strip()
print (line)
counter +=1
錯誤日志:
Error: java.io.IOException: subprocess exited successfully
R/W/S=6936/19/0 in:NA [rec/s] out:NA [rec/s]
minRecWrittenToEnableSkip_=9223372036854775807 HOST=null
USER=s2132211
HADOOP_USER=null
last tool output: |29670 YOU HAVE AATO|
Broken pipe
at org.apache.hadoop.streaming.PipeReducer.reduce(PipeReducer.java:129)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:444)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:392)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
首先,您的示例格式不正確,或者您有邏輯錯誤。 print(line)
和counter += 1
應該是INSIDE for循環。
更容易寫下來的方法是:
for counter, line in enumerate(fileinput.input()):
if(counter>limit):
break
line = line.strip()
print (line)
現在,如果這不能解決問題,那么問題就很少了。
1)你能看到程序的任何輸出(它實際上是從那個for循環中打印的東西)嗎?
2)程序是否立即崩潰,或者在一段時間后崩潰?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.