git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Append some stuff into a file with only the last appended line reserved.


On Tue, 03 Sep 2019 08:29:31 +1000, Cameron Simpson wrote:

> Please describe this in more detail. Present a little pycurl output and
> then explain what portion of it should land in the log file.

See the following code from here: 
http://pycurl.io/docs/latest/callbacks.html#xferinfofunction

----------------
## Callback function invoked when download/upload has progress
def progress(download_t, download_d, upload_t, upload_d):
    print "Total to download", download_t
    print "Total downloaded", download_d
    print "Total to upload", upload_t
    print "Total uploaded", upload_d

c = pycurl.Curl()
c.setopt(c.URL, "http://slashdot.org/";)
c.setopt(c.NOPROGRESS, False)
c.setopt(c.XFERINFOFUNCTION, progress)
c.perform()
--------------------


If I want to print these info ( or write them into log ) only when some 
specific events occur, say:

pycurl.ABORTED_BY_CALLBACK
pycurl.OPERTATION_TIMEOUT

How to do it?