Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lundgren examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rasmus Ringdahl
lundgren examples
Commits
c89d2ecd
Commit
c89d2ecd
authored
5 months ago
by
Rasmus Ringdahl
Browse files
Options
Downloads
Patches
Plain Diff
refactor: change to logging framework
parent
febe814b
No related branches found
No related tags found
1 merge request
!2
feat: add multi core job example
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
1_single_core_job/single_core_task.py
+10
-5
10 additions, 5 deletions
1_single_core_job/single_core_task.py
with
10 additions
and
5 deletions
1_single_core_job/single_core_task.py
+
10
−
5
View file @
c89d2ecd
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
(
'
\n
Job ID:
\t\t\t
{name}
\n
Job name:
\t\t
{id}
\n
Allocated cores:
\t
{cores}
\n
Allocated memory:
\t
{mem}
'
.
format
(
logger
.
info
(
'
\n
Job ID:
\t\t\t
%s
\n
Job name:
\t\t
%s
\n
Allocated cores:
\t
%s
\n
Allocated 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
(
'
\n
Job completed.
'
)
logger
.
info
(
'
Job completed.
'
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
main
()
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment