Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denisri committed Oct 13, 2023
1 parent 7a210ec commit e6f9524
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions capsul/engine/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ def worflow_loop(db_config, engine_id):
worker_id = database.worker_started(engine_id)
# print(f'!worker {worker_id}! started', engine_id)
try:
execution_id, job_uuid = database.pop_job(engine_id, start_time=datetime.now())
execution_id, job_uuid = database.pop_job(
engine_id, start_time=datetime.now())
while job_uuid is not None:
if not job_uuid:
# Empty string means no job available yet
time.sleep(0.2)
elif job_uuid == 'start_execution':
# print(f'!worker {worker_id}! start', execution_id)
# This part is done before the processing of any job
tmp = os.path.join(tempfile.gettempdir(), f'capsul_execution_{execution_id}')
tmp = os.path.join(tempfile.gettempdir(),
f'capsul_execution_{execution_id}')
os.mkdir(tmp)
try:
database.start_execution(engine_id, execution_id, tmp)
database.start_execution(engine_id, execution_id,
tmp)
except Exception:
os.rmdir(tmp)
elif job_uuid == 'end_execution':
Expand All @@ -46,12 +49,14 @@ def worflow_loop(db_config, engine_id):
debug=False,
)
# print(f'!worker {worker_id}! job', execution_id, job_uuid, database.job_finished)
database.job_finished(engine_id, execution_id, job_uuid,
end_time=datetime.now(),
return_code=return_code,
stdout=stdout,
stderr=stderr)
execution_id, job_uuid = database.pop_job(engine_id, start_time=datetime.now())
database.job_finished(engine_id, execution_id,
job_uuid,
end_time=datetime.now(),
return_code=return_code,
stdout=stdout,
stderr=stderr)
execution_id, job_uuid = database.pop_job(
engine_id, start_time=datetime.now())
finally:
# print(f'!worker {worker_id}! ended' )
database.worker_ended(engine_id, worker_id)
Expand All @@ -61,7 +66,8 @@ def worflow_loop(db_config, engine_id):

if __name__ == '__main__':
if len(sys.argv) != 3:
raise ValueError('This command must be called with two '
raise ValueError(
'This command must be called with two '
'parameters: an engine id and a database configuration')
engine_id = sys.argv[1]
db_config = json.loads(sys.argv[2])
Expand All @@ -72,7 +78,7 @@ def worflow_loop(db_config, engine_id):
if pid == 0:
os.setsid()
worflow_loop(db_config, engine_id)

# import cProfile
# import tempfile
# f = tempfile.mktemp(prefix='worker_profile_', dir='/tmp')
Expand Down

0 comments on commit e6f9524

Please sign in to comment.