Skip to main content

Async CSV performance logging

Project description

Async CSV Logger


This module is a async csv logger that helps you log performance of your algorithm.


This module is intented to be a csv logger which will write to file async-ly.

With the hope to have minimum performance impact on benchmarking your algorithm (i.e. I/O blocking to write to disk), this is especially useful for logging performance at each iteration/time-step. Internally, it utilise threading to async write to file.

There are two way to initialise and use the logger.


pip install asynccsv

1. Recommended way (with block)

import time
import datetime
from asynccsv import AsyncCSVLogger

with AsyncCSVLogger('path_of_your_log.csv') as logger:
    # csv titles
    logger.write(['Time', 'Accuracy', 'Num of nodes'])

    # do your other stuff
    # ......

    for i in range(10):
        # perform calculation
        # ....
        # write results to file
        logger.write(["%S.%f"), acc, num_nodes])

2. The normal way

import time
from asynccsv import AsyncCSVLogger

class MyAwesomeAlgorithm():

    def __init__(self):
        # with the 'log_timestamp' flag it will automatically log timestamp
        self.logger = AsyncCSVLogger('path_of_your_log.csv', log_timestamp=True)
        self.logger.write(['Time', 'Accuracy', 'Num of nodes'])

    def run(self):
        # perform calculation
        # ...
        logger.write([acc, num_nodes])

if __name__ == '__main__':
    awesome = MyAwesomeAlgorithm()
    for i in range(10):

    # You SHOULD run this to properly close the threading and force
    # everything to be written to disk
    # This is automatically done by the 'with' block in previous example

With both methods, the final content of path_of_your_log.csv will look something like:

"Time","Accuracy","Num of nodes"

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asynccsv-1.0.2.tar.gz (2.2 kB view hashes)

Uploaded Source

Built Distribution

asynccsv-1.0.2-py3-none-any.whl (2.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page