IPC::Open2 reporting error in sys.excepthook

Discussion in 'Perl Misc' started by Justin C, Jul 2, 2012.

  1. Justin C

    Justin C Guest

    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.
     
    Justin C, Jul 2, 2012
    #1
    1. Advertising

  2. Ben Morrow <> writes:
    > Quoth 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:

    >
    > 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).
     
    Rainer Weikusat, Jul 2, 2012
    #2
    1. Advertising

  3. Justin C

    Justin C Guest

    On 2012-07-02, Ben Morrow <> wrote:
    >
    > Quoth 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:

    >
    > 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.
     
    Justin C, Jul 3, 2012
    #3
  4. Justin C

    Justin C Guest

    On 2012-07-02, Rainer Weikusat <> wrote:
    > Ben Morrow <> writes:
    >> Quoth 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:

    >>
    >> 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.
     
    Justin C, Jul 3, 2012
    #4
  5. Justin C <> writes:
    > On 2012-07-02, Rainer Weikusat <> wrote:
    >> Ben Morrow <> writes:
    >>> Quoth 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:
    >>>
    >>> 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.
     
    Rainer Weikusat, Jul 3, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio
    Replies:
    0
    Views:
    661
    Antonio
    May 17, 2004
  2. grocery_stocker

    IPC::Open2 and sort

    grocery_stocker, Dec 9, 2006, in forum: Perl Misc
    Replies:
    12
    Views:
    191
    Joe Smith
    Dec 15, 2006
  3. Bernard Chan

    IPC::Open2 - Bad File Descriptor

    Bernard Chan, Mar 6, 2007, in forum: Perl Misc
    Replies:
    9
    Views:
    238
    Ben Morrow
    Mar 8, 2007
  4. Jerry Krinock
    Replies:
    9
    Views:
    277
    Jerry Krinock
    Sep 19, 2009
  5. Jai
    Replies:
    1
    Views:
    188
    Neil Cerutti
    Nov 19, 2013
Loading...

Share This Page