Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68287

Re: unittest weirdness

Date 2014-03-12 08:32 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: unittest weirdness
References <mailman.8062.1394573210.18130.python-list@python.org> <lfo1qj$3m3$1@reader1.panix.com> <lfokoh$3q3$1@ger.gmane.org> <mailman.8082.1394620172.18130.python-list@python.org> <roy-66F336.09444712032014@news.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.8095.1394640002.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 03/12/2014 06:44 AM, Roy Smith wrote:
> In article <mailman.8082.1394620172.18130.python-list@python.org>,
>   Ethan Furman <ethan@stoneleaf.us> wrote:
>
>> I've tried it both ways, and both ways my process is being killed, presumably
>> by the O/S.
>
> What evidence do you have the OS is killing the process?

I put a bare try/except around the call to unittest.main, with a print statement in the except, and nothing ever prints.


> Some systems have an oom (Out Of Memory) process killer, which nukes
> (semi-random) process when the system exhausts memory.  Is it possible
> this is happening?  If so, you should see some log message in one of
> your system logs.

That would explain why my editor windows were being killed.


> You didn't mention (or maybe I misssed it) which OS you're using.

Ubuntu 13 something or other.

> I'm
> assuming you've got some kind of system call tracer (strace, truss,
> dtrace, etc).

Sadly, I have no experience with those programs yet, and until now didn't even know they existed.

> Try running your tests under that.  If something is
> sending your process a kill signal, you'll see it:
>
> [gazillions of lines elided]
> write(1, ">>> ", 4>>> )                     = 4
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> select(1, [0], NULL, NULL, NULL)        = ? ERESTARTNOHAND (To be
> restarted)
> --- SIGTERM (Terminated) @ 0 (0) ---
> +++ killed by SIGTERM +++
>
> Alternatively, maybe something inside your process is just calling
> sys.exit(), or even os._exit().  You'll see the exit() system call in
> the strace output.

My bare try/except would have caught that.


> And, of course, the standard suggestion to reduce this down to the
> minimum test case.  You posted:
>
>       def test_xxx_1(self):
>           p = self.pp.lockbox_payments[0]
>           # affirm we have what we're expecting
>           self.assertEqual(
>                   (p.payer, p.ck_num, p.credit),
>                   ('a customer', '010101', 10000),
>                   )
>           self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX'])
>           self.assertEqual(p.invoices.values()[0].amount, 10000)
>           # now make sure we get back what we're expecting
>           np, b = self.pp._match_invoices(p)
>           missing = []
>           for inv_num in ('123456', '789012', '345678'):
>               if inv_num not in b:
>                   missing.append(inv_num)
>           if missing:
>               raise ValueError('invoices %r missing from batch' % missing)
>
> what happens if you reduce that to:
>
>       def test_xxx_1(self):
>            self.fail()

I only get the strange behavior if more than two (or maybe three) of my test cases fail.  Less than that magic number, 
and everything works just fine.  It doesn't matter which two or three, either.


> do you still get this strange behavior?  What if you get rid of your
> setUpClass()?  Keep hacking away at the test suite until you get down to
> a single line of code which, if run, exhibits the behavior, and if
> commented out, does not.  At that point, you'll have a clue what's
> causing this.  If you're lucky :-)

I strongly suspect it's memory.  When I originally wrote the code I tried to include six months worth of EoM data, but 
had to back it down to three as my process kept mysteriously dying at four or more months.  There must be waaaaaaay too 
much stuff being kept alive by the stack traces of the failed tests.

Thanks for your help!

--
~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-11 13:58 -0700
  Re: unittest weirdness John Gordon <gordon@panix.com> - 2014-03-11 22:13 +0000
    Re: unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-11 15:29 -0700
    Re: unittest weirdness Terry Reedy <tjreedy@udel.edu> - 2014-03-11 23:36 -0400
    Re: unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-12 03:03 -0700
      Re: unittest weirdness Roy Smith <roy@panix.com> - 2014-03-12 09:44 -0400
        Re: unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-12 08:32 -0700
          Re: unittest weirdness Roy Smith <roy@panix.com> - 2014-03-12 13:48 -0400
          Re: unittest weirdness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-12 23:14 +0000
          Re: unittest weirdness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-12 23:47 +0000
            Re: unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-12 17:31 -0700
        Re: unittest weirdness Terry Reedy <tjreedy@udel.edu> - 2014-03-12 22:27 -0400
  Re: unittest weirdness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-12 23:38 +0000
    Re: unittest weirdness Ethan Furman <ethan@stoneleaf.us> - 2014-03-12 17:36 -0700

csiph-web