IPC::Open2 reporting error in sys.excepthook

J

Justin C

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.
 
R

Rainer Weikusat

Ben Morrow said:
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).
 
J

Justin C

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]

$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.
 
J

Justin C

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.
 
R

Rainer Weikusat

Justin C said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top