multi thread: progress bar and real time logging
up vote
0
down vote
favorite
I must process around 45 000 items, it takes about 4 hours on a single core.
I want
- a progress bar to check the process is going forward
- to log errors while the process is running to eventually stop it if I observe it isn't going well enough.
The best I came with is displaying a progress bar but printing logs only at the very end of the process. It involves my function return a string (the log line) and print returned line after getting all the results. The real work creates files.
I get that I get all log lines at the very end of the process because I build the list of result (thus ending the process) before iterating over the log lines. But as I'm not used to multi threading, I don't see how to achieve what I'm aiming.
from multiprocessing import Pool
from tqdm import tqdm
def thread_safe_function(arg):
# do things
return log_line
if __name__ == '__main__':
for log in list(tqdm(pool.imap(thread_safe_function, input_list), total=len(pronunciation_models))):
print log
I guess the right solution would be to make my core function to print the logs but I didn't have any luck trying it. I believe either the threads my program created didn't share stdout with parent process (thus printing logs somewhere I wouldn't be able to read) or I misused Lock from multiprocessing.
def thread_safe_function(lock, arg):
# do things
if error:
lock.acquire()
print error
lock.release()
multithreading python-2.7 logging progress-bar
add a comment |
up vote
0
down vote
favorite
I must process around 45 000 items, it takes about 4 hours on a single core.
I want
- a progress bar to check the process is going forward
- to log errors while the process is running to eventually stop it if I observe it isn't going well enough.
The best I came with is displaying a progress bar but printing logs only at the very end of the process. It involves my function return a string (the log line) and print returned line after getting all the results. The real work creates files.
I get that I get all log lines at the very end of the process because I build the list of result (thus ending the process) before iterating over the log lines. But as I'm not used to multi threading, I don't see how to achieve what I'm aiming.
from multiprocessing import Pool
from tqdm import tqdm
def thread_safe_function(arg):
# do things
return log_line
if __name__ == '__main__':
for log in list(tqdm(pool.imap(thread_safe_function, input_list), total=len(pronunciation_models))):
print log
I guess the right solution would be to make my core function to print the logs but I didn't have any luck trying it. I believe either the threads my program created didn't share stdout with parent process (thus printing logs somewhere I wouldn't be able to read) or I misused Lock from multiprocessing.
def thread_safe_function(lock, arg):
# do things
if error:
lock.acquire()
print error
lock.release()
multithreading python-2.7 logging progress-bar
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I must process around 45 000 items, it takes about 4 hours on a single core.
I want
- a progress bar to check the process is going forward
- to log errors while the process is running to eventually stop it if I observe it isn't going well enough.
The best I came with is displaying a progress bar but printing logs only at the very end of the process. It involves my function return a string (the log line) and print returned line after getting all the results. The real work creates files.
I get that I get all log lines at the very end of the process because I build the list of result (thus ending the process) before iterating over the log lines. But as I'm not used to multi threading, I don't see how to achieve what I'm aiming.
from multiprocessing import Pool
from tqdm import tqdm
def thread_safe_function(arg):
# do things
return log_line
if __name__ == '__main__':
for log in list(tqdm(pool.imap(thread_safe_function, input_list), total=len(pronunciation_models))):
print log
I guess the right solution would be to make my core function to print the logs but I didn't have any luck trying it. I believe either the threads my program created didn't share stdout with parent process (thus printing logs somewhere I wouldn't be able to read) or I misused Lock from multiprocessing.
def thread_safe_function(lock, arg):
# do things
if error:
lock.acquire()
print error
lock.release()
multithreading python-2.7 logging progress-bar
I must process around 45 000 items, it takes about 4 hours on a single core.
I want
- a progress bar to check the process is going forward
- to log errors while the process is running to eventually stop it if I observe it isn't going well enough.
The best I came with is displaying a progress bar but printing logs only at the very end of the process. It involves my function return a string (the log line) and print returned line after getting all the results. The real work creates files.
I get that I get all log lines at the very end of the process because I build the list of result (thus ending the process) before iterating over the log lines. But as I'm not used to multi threading, I don't see how to achieve what I'm aiming.
from multiprocessing import Pool
from tqdm import tqdm
def thread_safe_function(arg):
# do things
return log_line
if __name__ == '__main__':
for log in list(tqdm(pool.imap(thread_safe_function, input_list), total=len(pronunciation_models))):
print log
I guess the right solution would be to make my core function to print the logs but I didn't have any luck trying it. I believe either the threads my program created didn't share stdout with parent process (thus printing logs somewhere I wouldn't be able to read) or I misused Lock from multiprocessing.
def thread_safe_function(lock, arg):
# do things
if error:
lock.acquire()
print error
lock.release()
multithreading python-2.7 logging progress-bar
multithreading python-2.7 logging progress-bar
asked Nov 9 at 13:01
Adrien H
11416
11416
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17
add a comment |
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226208%2fmulti-thread-progress-bar-and-real-time-logging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I found stackoverflow.com/questions/20056300/… but I am not able to use it I get TypeError: can't pickle thread.lock objects
– Adrien H
Nov 9 at 13:17