Don't ask to ask, just ask | |
PerlMonks |
Re: Redirecting output in Windows cmd prevents second thread from doing anythingby dasgar (Priest) |
on Jan 15, 2016 at 19:23 UTC ( [id://1152889]=note: print w/replies, xml ) | Need Help?? |
First, just wanted to point out that the documentation for the Thread module indicates that it is deprecated and recommends users to use the threads module instead (see DEPRECATED section). That has nothing to do with your question, but might help you to avoid other issues down the road. For creating a log of everything from all of the threads, you could create a variable in each thread that would contain the log contents of that thread and have the thread return that value. Then the main code section can print that out to a file afterwards. Here's an untested modification of your code that will does what I just described.
Of course, one drawback on that would be that if a thread were to die prematurely, you would lose all logging for that thread. Since you are already using a shared variable for the threads to read from, you could also use one or more shared variables that the threads could use for logging. And again, write that out to file after joining all of the threads. And if you are needing/wanting the logging to be intermixed, just add a timestamp for each log entry from each thread. Then you could sort the entries from all of the logs afterwards to create a single chronologically ordered log from the contents of all of the thread logs.
In Section
Seekers of Perl Wisdom
|
|