fert has asked for the wisdom of the Perl Monks concerning the following question:
I'm hoping somebody can shed some light on what is going on here. The quick and dirty reduced examples. Say we want to print a UTF8 character inside a function, to avoid warnings we must explicitly call binmode like this:
(in Perl v5.8.8)
my $char = "\x{30DE}\x{30A4}\x{30AF}"; binmode STDOUT, ":utf8"; out(); sub out { print "$char"; }
Works fine, prints out the character.
But as soon as we thread things up...
use threads; my $char = "\x{30DE}\x{30A4}\x{30AF}"; binmode STDOUT, ":utf8"; my $thr = threads->create(\&foo); $thr->join; sub foo { print "$char"; }
We get the "wide character print".
Is this known/expected behavior of a FileHandle? I can make the message go away with another binmode inside of the function, but since I'm getting this error out of Log4Perl changing the inards is something I am hoping to avoid. The bigger picture if you are interested. I am using Log4Perl with syswrite turned on to try and allow multiple threads to write to a single log file. Because of the threading(I think) anytime a utf8 character goes through the Appender (File), the utf8 bit is set to true, but only gets binmoded on creation of the Appender, not in what I am guessing is the copies that the thread has created. The file handle is no longer set to be utf8 so it dies, which causes the whole thread to die.
So the warning thrown to the Appender causes it to call a die, and subsequently my thread to die. I've put in a binmode to the source and it seems to work but am hesitant to assume I've fixed it completely.
I'm not sure if this is something the Log4Perl should be aware of or need to fix or if its something I am doing wrong, any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filehandles, threads, utf8 reset?
by ikegami (Patriarch) on Apr 20, 2010 at 23:21 UTC | |
by fert (Acolyte) on Apr 20, 2010 at 23:29 UTC | |
by ikegami (Patriarch) on Apr 21, 2010 at 00:36 UTC | |
by fert (Acolyte) on Apr 30, 2010 at 21:29 UTC | |
|
Re: Filehandles, threads, utf8 reset?
by choroba (Cardinal) on Apr 20, 2010 at 22:26 UTC |