Open p5pRT opened 15 years ago
This program prints "here" only once\, when one would naively expect it to print it twice:
BEGIN { fork } warn "here\n";
I guess this is because the parser exhausts the file\, so the next run will hit EOF immediately\, as this is in the middle of the parse.
I think this should either be fixed\, or the parse file handle be made accessible (perl programs can't really be responsible for implementation details they have no access to - if all the open parser fh's would be accessible it could be made the responsibility of the perl program to get it right).
2009/8/2 perlbug@plan9.de (via RT) \perlbug\-followup@​perl\.org:
This program prints "here" only once\, when one would naively expect it to print it twice:
BEGIN { fork } warn "here\n";
I guess this is because the parser exhausts the file\, so the next run will hit EOF immediately\, as this is in the middle of the parse.
I think this should either be fixed\, or the parse file handle be made accessible (perl programs can't really be responsible for implementation details they have no access to - if all the open parser fh's would be accessible it could be made the responsibility of the perl program to get it right).
Note that a simple workaround to this behaviour is to use __DATA__ and its filehandle\, and rewind it\, as in:
seek DATA\,0\,0; print '-'x20\,"\n"; print for \; print '-'x20\,"\n"; __DATA__
The RT System itself - Status changed from 'new' to 'open'
On Thu\, Aug 06\, 2009 at 04:57:51PM +0200\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
I think this should either be fixed\, or the parse file handle be made accessible (perl programs can't really be responsible for implementation details they have no access to - if all the open parser fh's would be accessible it could be made the responsibility of the perl program to get it right).
Note that a simple workaround to this behaviour is to use __DATA__ and its filehandle\, and rewind it\, as in:
Just stumbled over your reply by accident (you didn't send it to me\, of course).
Please note that your example does not work\, because DATA is not available in a BEGIN block\, nor does it work when the code is used in a module.
The workaround I use in Anyevent::Watchdog is this\, which is of coruse rather painful\, but works fine:
Before fork:
our %SEEKPOS; # due to bugs in perl\, try to remember file offsets for all fds\, and restore them later # (the parser otherwise exhausts the input files)
# this causes perlio to flush it's handles internally\, so # seek offsets become correct. exec "."; # toi toi toi
# now records all fd positions for (0 .. 1023) { open my $fh\, "\<&$_" or next; $SEEKPOS{$_} = (sysseek $fh\, 0\, 1 or next); }
After each fork:
# restore seek offsets while (my ($k\, $v) = each %SEEKPOS) { open my $fh\, "\<&$k" or next; sysseek $fh\, $v\, 0; }
The code is so ugly because there is no way to access the file handles in any other way (the parser doesn't expose them)\, and that I need an exec to reify the file offsets so I cna query them (a dummy fork would work\, too\, and is probably cleaner).
Since it seems to work\, I am fine with that as long as I do not have to look at the code. It would be nice if the perl parser would support forking\, however.
-- The choice of a Deliantra\, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / pcg@goof.com -=====/_/_//_/\_\,_/ /_/\_\
2009/8/26 Marc Lehmann \schmorp@​schmorp\.de:
On Thu\, Aug 06\, 2009 at 04:57:51PM +0200\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
I think this should either be fixed\, or the parse file handle be made accessible (perl programs can't really be responsible for implementation details they have no access to - if all the open parser fh's would be accessible it could be made the responsibility of the perl program to get it right).
Note that a simple workaround to this behaviour is to use __DATA__ and its filehandle\, and rewind it\, as in:
Just stumbled over your reply by accident (you didn't send it to me\, of course).
No. Your mail address wasn't in the From or in the Reply-To headers. RT should have forwarded my email to you\, but apparently that did not happen. Am I understanding correctly what RT should do here ?
Please note that your example does not work\, because DATA is not available in a BEGIN block\, nor does it work when the code is used in a module.
Yes. That was a specific workaround for simple cases.
The workaround I use in Anyevent::Watchdog is this\, which is of coruse rather painful\, but works fine:
Before fork:
our %SEEKPOS; # due to bugs in perl\, try to remember file offsets for all fds\, and restore them later # (the parser otherwise exhausts the input files)
# this causes perlio to flush it's handles internally\, so # seek offsets become correct. exec "."; # toi toi toi
# now records all fd positions for (0 .. 1023) { open my $fh\, "\<&$_" or next; $SEEKPOS{$_} = (sysseek $fh\, 0\, 1 or next); }
After each fork:
# restore seek offsets while (my ($k\, $v) = each %SEEKPOS) { open my $fh\, "\<&$k" or next; sysseek $fh\, $v\, 0; }
The code is so ugly because there is no way to access the file handles in any other way (the parser doesn't expose them)\, and that I need an exec to reify the file offsets so I cna query them (a dummy fork would work\, too\, and is probably cleaner).
Since it seems to work\, I am fine with that as long as I do not have to look at the code. It would be nice if the perl parser would support forking\, however.
I agree. I think that IlyaZ encountered the same problem some years ago and even proposed the start of the solution.
On Wed\, Aug 26\, 2009 at 11:06:55AM +0200\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
Just stumbled over your reply by accident (you didn't send it to me\, of course).
No. Your mail address wasn't in the From or in the Reply-To headers.
Oh right\, rt.cpan.org has this annoying habit of remoivng e-mail addresses.
RT should have forwarded my email to you\, but apparently that did not happen. Am I understanding correctly what RT should do here ?
I don't know - normally I receive replies to perlbug-reports. Not a big deal in any case.
Since it seems to work\, I am fine with that as long as I do not have to look at the code. It would be nice if the perl parser would support forking\, however.
I agree. I think that IlyaZ encountered the same problem some years ago and even proposed the start of the solution.
Well\, I can live with havign to do some extra work - the problem isn't exactly high-priority. It's just that my workaround is beyond evil (especially the dummy exec\, relying on even more internals).
But as it seems to work\, I can live with it for the time being.
(Maybe it should just be documented - that fork doesn't work in BEGIN under windows is actually mentioned somewhere).
-- The choice of a Deliantra\, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / pcg@goof.com -=====/_/_//_/\_\,_/ /_/\_\
Migrated from rt.perl.org#68118 (status was 'open')
Searchable as RT68118$