Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9342
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <t@jollybox.de> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'terry': 0.07; 'caller': 0.09; 'line:': 0.09; 'am,': 0.13; 'subject:file': 0.13; 'wrote:': 0.15; "'rb')": 0.16; 'billy': 0.16; 'received:192.168.1.40': 0.16; 'pm,': 0.16; '>>>': 0.16; 'def': 0.16; 'any,': 0.19; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; 'function': 0.26; "i'm": 0.27; 'raise': 0.28; 'yield': 0.29; 'problem': 0.29; 'confused': 0.30; 'tail': 0.30; 'lines': 0.31; 'actually': 0.33; 'to:addr:python-list': 0.34; 'header:User- Agent:1': 0.34; 'there': 0.34; 'then.': 0.35; '(not': 0.35; 'subject:How': 0.36; 'skip:o 20': 0.36; 'file': 0.36; 'but': 0.37; 'received:192': 0.38; 'subject:: ': 0.38; 'received:192.168.1': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'read,': 0.40; 'called': 0.40; 'bill': 0.40; 'received:62': 0.67; '04:46': 0.84; 'avoid.': 0.84; 'from:addr:t': 0.84; 'subject:write': 0.84 |
| Date | Tue, 12 Jul 2011 21:05:52 +0200 |
| From | Thomas Jollans <t@jollybox.de> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110626 Iceowl/1.0b2 Icedove/3.1.11 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: How to write a file generator |
| References | <ivhmoc$6t3$1@speranza.aioe.org> <mailman.944.1310485982.1164.python-list@python.org> <ivhthn$peg$1@speranza.aioe.org> |
| In-Reply-To | <ivhthn$peg$1@speranza.aioe.org> |
| X-Enigmail-Version | 1.1.2 |
| OpenPGP | id=5C8691ED |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.952.1310497555.1164.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1310497555 news.xs4all.nl 23861 [2001:888:2000:d::a6]:37083 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:9342 |
Show key headers only | View raw
On 07/12/2011 06:42 PM, Billy Mays wrote:
> On 07/12/2011 11:52 AM, Thomas Jollans wrote:
>> On 07/12/2011 04:46 PM, Billy Mays wrote:
>>> I want to make a generator that will return lines from the tail of
>>> /var/log/syslog if there are any, but my function is reopening the file
>>> each call:
>>>
>>> def getLines():
>>> with open('/var/log/syslog', 'rb') as f:
>>> while True:
>>> line = f.readline()
>>> if line:
>>> yield line
>>> else:
>>> raise StopIteration
>>>
>>>
>>> I know the problem lies with the StopIteration, but I'm not sure how to
>>> tell the caller that there are no more lines for now.
>>>
>>> --
>>> Bill
>>
>> http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep
>>
>
>
> That was actually the behavior I was trying to avoid. If there is no
> data to be read, the call will hang. That function is actually called
> by a webserver (from wsgiref) so it cannot hang indefinitely.
What Terry said, then. (Not Bruno, I confused that. Sorry for sending a
mail both short and wrong.)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to write a file generator Billy Mays <noway@nohow.com> - 2011-07-12 10:46 -0400
Re: How to write a file generator "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-07-12 08:34 -0700
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 17:52 +0200
Re: How to write a file generator Billy Mays <noway@nohow.com> - 2011-07-12 12:42 -0400
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 21:04 +0200
Re: How to write a file generator Thomas Jollans <t@jollybox.de> - 2011-07-12 21:05 +0200
Re: How to write a file generator sturlamolden <sturlamolden@yahoo.no> - 2011-07-12 09:53 -0700
Re: How to write a file generator Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-07-13 01:26 +0200
csiph-web