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()









share|improve this question






















  • 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















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()









share|improve this question






















  • 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













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()









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Android Play Services Check

Where to put API Key in Google Cloud Vision for PHP