Skip to content
Snippets Groups Projects
Commit c89d2ecd authored by Rasmus Ringdahl's avatar Rasmus Ringdahl
Browse files

refactor: change to logging framework

parent febe814b
No related branches found
No related tags found
1 merge request!2feat: add multi core job example
from datetime import datetime from datetime import datetime
import time
import logging
import os import os
import time
logger = logging.getLogger(__name__)
def main(): def main():
# Read environment variables. # Read environment variables.
...@@ -13,12 +17,12 @@ def main(): ...@@ -13,12 +17,12 @@ def main():
# This represents the calculations # This represents the calculations
current_time = datetime.now() current_time = datetime.now()
sleep_time = 60 - current_time.second sleep_time = 60 - current_time.second
print('{} - Sleeping for {} seconds.'.format(current_time.strftime('%Y-%m-%d %H:%M:%S'), sleep_time)) logger.info('%s - Sleeping for %d seconds.',current_time.strftime('%Y-%m-%d %H:%M:%S'), sleep_time)
time.sleep(sleep_time) time.sleep(sleep_time)
# Printing some things to standard output. # Printing some things to standard output.
print('\nJob ID:\t\t\t{name}\nJob name:\t\t{id}\nAllocated cores:\t{cores}\nAllocated memory:\t{mem}'.format( logger.info('\nJob ID:\t\t\t%s\nJob name:\t\t%s\nAllocated cores:\t%s\nAllocated memory:\t%s',
id=JOB_ID, name=JOB_NAME, cores=NUMBER_OF_CORES,mem=MAXIMUM_MEMORY)) JOB_ID, JOB_NAME, NUMBER_OF_CORES,MAXIMUM_MEMORY)
# Writing some output to a file based on the Slurm job id. # Writing some output to a file based on the Slurm job id.
output_file = '{}.txt'.format(JOB_ID) output_file = '{}.txt'.format(JOB_ID)
...@@ -26,7 +30,8 @@ def main(): ...@@ -26,7 +30,8 @@ def main():
file.write('This file was created by the job {} with id {}\n'.format file.write('This file was created by the job {} with id {}\n'.format
(JOB_NAME, JOB_ID)) (JOB_NAME, JOB_ID))
print('\nJob completed.') logger.info('Job completed.')
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment