diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-02 14:58:31 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-02 14:58:31 -0400 |
commit | 9028e5ef90c1b7f5a42c6bf969ac3c838b570a7e (patch) | |
tree | f167c6de681ad68650081145d4092322877af141 | |
parent | 04cf9ee4f65c1d0b2b60b9ac87cd91c0a333889e (diff) | |
download | stasis-9028e5ef90c1b7f5a42c6bf969ac3c838b570a7e.tar.gz |
Allow user to define the time interval for "task is running" message
-rw-r--r-- | src/multiprocessing.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/multiprocessing.c b/src/multiprocessing.c index 1c585ff..baa6df7 100644 --- a/src/multiprocessing.c +++ b/src/multiprocessing.c @@ -240,10 +240,10 @@ int mp_pool_kill(struct MultiProcessingPool *pool, int signum) { int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { int status = 0; int failures = 0; - time_t watcher = time(NULL); size_t tasks_complete = 0; size_t lower_i = 0; size_t upper_i = jobs; + do { size_t hang_check = 0; if (upper_i >= pool->num_used) { @@ -349,11 +349,16 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { fprintf(stderr, "waitpid failed: %s\n", strerror(errno)); return -1; } else { - time_t watcher_diff = time(NULL) - watcher; - if (watcher_diff == 0) { + // Track the number of seconds elapsed for each task. + // When a task has executed for longer than status_intervals, print a status update + // _seconds represents the time between intervals, not the total runtime of the task + slot->_seconds = time(NULL) - slot->_now; + if (slot->_seconds > pool->status_interval) { + slot->_now = time(NULL); + slot->_seconds = 0; + } + if (slot->_seconds == 0) { printf("[%s:%s] Task is running (pid: %d)\n", pool->ident, slot->ident, slot->parent_pid); - } else if (watcher_diff > 9) { - watcher = time(NULL); } } } |