![]() |
IPC::Open2 reporting error in sys.excepthook
I can't see what I'm doing wrong here. My program is doing what I want it to do, using a module I wrote to interface with Mailman, but I'm getting: GLOB(0x2d86348)close failed in file object destructor: Error in sys.excepthook: Original exception was: My program extracts recently added email addresses from a database of prospects and adds them to Mailman mailing list manager using the commandline Mailman tools: package MyModules::Mailman; use strict; use Carp; use IPC::Open2 sub add_subscribers { my (undef, $mailinglist, $addresses) = @_; my ($in, $out, $pid) = connect_to_list($mailinglist); for my $address (@{ $addresses }) { print {$in} $address, "\n"; print {$out} "Added: <$address>\n"; } close $in; close $out; waitpid($pid, 0); my $exit_status = $? >> 8; print "Exit status: ", $exit_status, "/n" if $exit_status; } sub connect_to_list { my $mailinglist = shift; my $cmd = '/usr/lib/mailman/bin/add_members'; my @opts = ('--regular-members-file=-', '--welcome-msg=n', '--admin-notify=n'); my @args = ($cmd, @opts, $mailinglist); my ($in, $out); my $pid = open2($out, $in, @args); return ($in, $out, $pid); } 1; ======= I believe the problem is within the module, and not the calling program, which uses the module thusly: use strict; use warnings; use MyModules; my $results = extract_new_addresses(); # an arrayref to list of email addresses my $return_val = MyModule::Mailman->add_subscribers('prospects', $results); print "Return value: ", $return_val, "\n"; ======= I usually spot any howlers when I prepare these messages, but nothing has jumped out at me. Any suggestions why I'm getting the error would be gratefully received. Justin. -- Justin C, by the sea. |
Re: IPC::Open2 reporting error in sys.excepthook
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Justin C <justin.1207@purestblue.com>: >> >> I can't see what I'm doing wrong here. My program is doing what >> I want it to do, using a module I wrote to interface with >> Mailman, but I'm getting: >> >> GLOB(0x2d86348)close failed in file object destructor: >> Error in sys.excepthook: > > This is a Python error, which means it's coming from Mailman. I'm afraid > I don't know what it means. According to http://bugs.python.org/issue4192, it means "don't close your end of the pipe the client is supposed to write to before it has terminated" (meaning, do wait(); close(...); not the other way round (explicit close can usually be omitted in Perl which should solve the problem as well). |
Re: IPC::Open2 reporting error in sys.excepthook
On 2012-07-02, Ben Morrow <ben@morrow.me.uk> wrote:
> > Quoth Justin C <justin.1207@purestblue.com>: >> >> I can't see what I'm doing wrong here. My program is doing what >> I want it to do, using a module I wrote to interface with >> Mailman, but I'm getting: >> >> GLOB(0x2d86348)close failed in file object destructor: >> Error in sys.excepthook: > > This is a Python error, which means it's coming from Mailman. I'm afraid > I don't know what it means. Thank you for the clue, I'll go and start looking elsewhere. [snip] >> print {$out} "Added: <$address>\n"; > > $out is for reading from Mailman. Why are you trying to write to it? I have no idea! The line is to tell me what I've done; why I'm trying to print it there I have no idea. Justin. -- Justin C, by the sea. |
Re: IPC::Open2 reporting error in sys.excepthook
On 2012-07-02, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> Ben Morrow <ben@morrow.me.uk> writes: >> Quoth Justin C <justin.1207@purestblue.com>: >>> >>> I can't see what I'm doing wrong here. My program is doing what >>> I want it to do, using a module I wrote to interface with >>> Mailman, but I'm getting: >>> >>> GLOB(0x2d86348)close failed in file object destructor: >>> Error in sys.excepthook: >> >> This is a Python error, which means it's coming from Mailman. I'm afraid >> I don't know what it means. > > According to http://bugs.python.org/issue4192, it means "don't close > your end of the pipe the client is supposed to write to before it has > terminated" (meaning, do > > wait(); > close(...); > > not the other way round (explicit close can usually be omitted in > Perl which should solve the problem as well). But if I don't 'close' my program doesn't end, the Mailman part (IPC::Open2) sits there waiting for further input, but there isn't any. A little experimentation, it is only my closing the $out that causes the problem so I've removed it and I'm leaving it to perl to sort out. Problem resolved. Thanks for the replies. Justin. -- Justin C, by the sea. |
Re: IPC::Open2 reporting error in sys.excepthook
Justin C <justin.1207@purestblue.com> writes:
> On 2012-07-02, Rainer Weikusat <rweikusat@mssgmbh.com> wrote: >> Ben Morrow <ben@morrow.me.uk> writes: >>> Quoth Justin C <justin.1207@purestblue.com>: >>>> >>>> I can't see what I'm doing wrong here. My program is doing what >>>> I want it to do, using a module I wrote to interface with >>>> Mailman, but I'm getting: >>>> >>>> GLOB(0x2d86348)close failed in file object destructor: >>>> Error in sys.excepthook: >>> >>> This is a Python error, which means it's coming from Mailman. I'm afraid >>> I don't know what it means. >> >> According to http://bugs.python.org/issue4192, it means "don't close >> your end of the pipe the client is supposed to write to before it has >> terminated" (meaning, do >> >> wait(); >> close(...); >> >> not the other way round (explicit close can usually be omitted in >> Perl which should solve the problem as well). > > But if I don't 'close' my program doesn't end, the Mailman part > (IPC::Open2) sits there waiting for further input, but there > isn't any. > > A little experimentation, it is only my closing the $out that > causes the problem That's the exact same thing I wrote ('don't close your end of the pipe the client is supposed to write to before it has terminated') and also stated in the text the link points to, This happens because when flooder.py terminates, its stdout will be closed, but another pipe end in receirver.py process is already closed, so Python\sysmodule.c(1098): _check_and_flush (FILE *stream) In this function, fflush() fails. Most likely (I haven't tested this), the reason is that there's some buffered output and when fflush tries to write that to 'a broken pipe', the results is either a SIGPIPE signal or an EPIPE error. Explicit close can usually be omitted in Perl, namely, when the close is just being done because someone felt like being anal about this for no particular reason, as in your code, and simply not closing this filehandle for no purpose will solve the problem. |
| All times are GMT. The time now is 07:41 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.