Script continues running after an exit() call?

Discussion in 'Perl Misc' started by Debo, Jun 15, 2005.

  1. Debo

    Debo Guest

    I realize this post is going to be noninformative, but the script I'm
    writing is rather long and so in the interest of brevity I'd like to just
    summarize the problem I'm having.

    I've written a script that, in general terms:

    1. Opens a log file for writing, using Log:Log4Perl

    1. Uses system() to call a program (NCBI BLAST) to associate the data in
    two files. BLAST writes out a report of its activity. This report is quite
    large (~600 megs).

    2. Opens a handle to a postgres database (with AutoCommit off) using DBI.

    3. Creates a cached INSERT query, and then parses the report, using this
    query to insert lots (~20000) records based on this report. Some of the
    insertions fail, but that doesn't really concern me because I sort of
    expect the process to be lossy. (I don't know if this screws up the
    ability to commit the changes).

    4. Commits the changes to the database.

    5. Uses the move() method of File::Copy to move the log file to a
    different location.

    6. Calls exit(0)

    Now, here's the rub. The script will sometimes succeed or sometimes fail
    to commit, which I think I can fix without much difficulty. However, when
    I run this overnight and return in the morning, I INVARIABLY find about
    18-20 perl processes running, and the BLAST command still running.

    I look at the log that the script generates (in its new location, after
    the move() call), and it seems that after the script reaches the exit(0),
    it starts the BLAST process again, and continues to do so repeatedly. In
    all, BLAST will be called and will complete execution about 3 or 4 times
    throughout the course of the night, when the flow of control in the script
    quite obviously shows that it should only execute once.

    The thing I find especially strange is that the script continues to log
    changes to the log file *after it has been moved*! It does this regardless
    of whether I use the logger, or a plain filehandle to do my logging. The
    script does not output anything pertaining to this problem on stderr (it's
    mostly just some gunk that bioperl spits out for no particular reason).

    So, I suppose my questions are:

    1) Under what circumstances would perl be enticed to spawn a legion of
    subprocesses without any explicit fork etc calls in the script?

    2) How could these processes continue to write to a file after it has been
    moved?

    3) Why would a script 'ignore' an exit(0) call?

    My platform right now is cygwin (shudder) with perl v5.8.5. I'd love
    to be doing this in linux, but external forces have imposed the
    environment and now i'm stuck with it.

    Any tips you could provide that would help me diagnose the problem would be
    appreciated.

    Thanks!

    -Debo
    Debo, Jun 15, 2005
    #1
    1. Advertising

  2. Debo

    Jim Keenan Guest

    Debo wrote:
    > I realize this post is going to be noninformative, but the script I'm
    > writing is rather long and so in the interest of brevity I'd like to just
    > summarize the problem I'm having.
    >


    Since there are at least a half-dozen places where your script could be
    going awry, I can't give anything like a definitive answer. But, if
    you haven't done so already, I would populate the script with calls to
    "die" with appropriate error messages and see how far the script gets
    when certain conditions are not met.

    jimk
    Jim Keenan, Jun 15, 2005
    #2
    1. Advertising

  3. Debo

    Guest

    Debo <> wrote:
    >
    > The thing I find especially strange is that the script continues to log
    > changes to the log file *after it has been moved*! It does this
    > regardless of whether I use the logger, or a plain filehandle to do my
    > logging.


    On unix/linux, moving a file (within a file system) is little more than
    a change in name. It doesn't effect any already-open handles to that file.

    > The script does not output anything pertaining to this problem
    > on stderr (it's mostly just some gunk that bioperl spits out for no
    > particular reason).


    I'd suggest you liberally sprinkle your code with "warn" statements.

    warn "$$ I'm about to start BLAST";
    #...
    warn "$$ I've just finished BLAST";
    #...
    warn "$$ I'm about to exit";


    >
    > So, I suppose my questions are:
    >
    > 1) Under what circumstances would perl be enticed to spawn a legion of
    > subprocesses without any explicit fork etc calls in the script?


    You are probably mis-interpreting something.

    > 3) Why would a script 'ignore' an exit(0) call?


    You are probably mis-interpreting something.
    You might want to try POSIX::_exit, though I doubt that will
    be the problem.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Jun 15, 2005
    #3
  4. Debo

    Guest

    Debo wrote:
    > I realize this post is going to be noninformative, but the script I'm
    > writing is rather long and so in the interest of brevity I'd like to just
    > summarize the problem I'm having.
    >
    > I've written a script that, in general terms:
    >
    > 1. Opens a log file for writing, using Log:Log4Perl
    >

    [---]

    > 5. Uses the move() method of File::Copy to move the log file to a
    > different location.
    >
    > 6. Calls exit(0)
    >


    Hmmm- do you close the logfile before doing the move?

    [---]

    > Thanks!
    >
    > -Debo


    HTH-
    kDot
    , Jun 18, 2005
    #4
    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. ENathan

    code continues after stop debugging

    ENathan, Jun 9, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    485
    Craig Deelsnyder
    Jun 10, 2005
  2. Chris P.
    Replies:
    7
    Views:
    310
    Chris P.
    Jul 20, 2004
  3. Replies:
    2
    Views:
    444
    Jeff Epler
    May 31, 2005
  4. Li Chen
    Replies:
    20
    Views:
    275
    Brian Candler
    Sep 21, 2008
  5. David Sokoloff

    Script Won't Exit After Call to System

    David Sokoloff, Mar 8, 2009, in forum: Ruby
    Replies:
    1
    Views:
    154
    Brian Candler
    Mar 8, 2009
Loading...

Share This Page