-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use threading to run jobmanager loop #614
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I'm not sure we should do this with asyncio, as everything (HTTP requests, file IO) are just classic blocking calls currently, so there is not much to gain.
I think in this case working with Python threading
will be a bit simpler
openeo/extra/job_management.py
Outdated
@@ -252,6 +255,43 @@ def _normalize_df(self, df: pd.DataFrame) -> pd.DataFrame: | |||
|
|||
return df | |||
|
|||
def start_job_thread(self,start_job: Callable[[], BatchJob], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using "thread" in naming and docs might be confusing and setting wrong expectations as asyncio is not about threading but coroutines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's now converted to use an actual 'Thread' object, so the confusion is gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soxofaan if this is fine now, we can merge and continue with the other PR's
tests/extra/test_job_management.py
Outdated
year = int(row["year"]) | ||
return BatchJob(job_id=f"job-{year}", connection=connection) | ||
|
||
df = manager._normalize_df(df) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this normalize_df be handled automatically in the manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we lack a good mechanism to initialize a job db correctly, we'll have to come up with something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soxofaan I introduced initialize_job_db to address this issue.
(using darker and isort)
and avoid infinite wait (by default)
FYI: I pushed some tweaks (some automatic code style cleanups), but more importantly some tweaks to the sleep/wait logic in 95a4ec7. Feel free to revert |
tests/extra/test_job_management.py
Outdated
return BatchJob(job_id=f"job-{year}", connection=connection) | ||
|
||
job_db = CsvJobDatabase(output_file) | ||
manager.initialize_job_db(job_db, df) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soxofaan I introduced initialize_job_db to address this issue.
I see, but I'd think that this initialization is not something the user should be bothered with,
can't this just be done automatically like in run_jobs
:
openeo-python-client/openeo/extra/job_management.py
Lines 358 to 363 in 0c2fdc1
if job_db.exists(): | |
# Resume from existing db | |
_log.info(f"Resuming `run_jobs` from existing {job_db}") | |
elif df is not None: | |
df = self._normalize_df(df) | |
job_db.persist(df) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To initialize a job db, you need a dataframe (once), I try to avoid that, due to the confusion that Victor explained here:
#607 (comment)
db initialization API needs some more thought, which is for another PR
db initialization API needs some more thought, which is for another PR
remove the |
I propose to allow running the jobmanager cycle in a separate thread, allowing for a more clean option to interrupt it.