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


Groups > comp.lang.python > #94304

Re: Noob in Python. Problem with fairly simple test case

Newsgroups comp.lang.python
Date 2015-07-21 10:38 -0700
References <0165e508-b3b4-4a95-b1bb-e115893056f8@googlegroups.com> <mailman.539.1436962316.3674.python-list@python.org>
Message-ID <40474894-45e0-46fd-92b8-486b83d23d29@googlegroups.com> (permalink)
Subject Re: Noob in Python. Problem with fairly simple test case
From "Jason P." <suscricions@gmail.com>

Show all headers | View raw


El miércoles, 15 de julio de 2015, 14:12:08 (UTC+2), Chris Angelico  escribió:
> On Wed, Jul 15, 2015 at 9:44 PM, Jason P. <suscricions@gmail.com> wrote:
> > I can't understand very well what's happening. It seems that the main thread gets blocked listening to the web server. My intent was to spawn another process for the server independent of the test. Obviously I'm doing something wrong. I've made several guesses commenting pieces of code (tearDown method for example) but I didn't manage to solve the problem(s).
> >
> 
> When you find yourself making guesses to try to figure out what's
> going on, here are two general tips:
> 
> 1) Cut out as many pieces as you can. Test one small thing at a time.
> 2) If In Doubt, Print It Out! Stick print() calls into the code at key
> places, displaying the values of parameters or the results of
> intermediate calculations - or just saying "Hi, I'm still here and I'm
> running!".
> 
> For #1, I would recommend first just trying to get the web service
> going. Can you connect (using an external program) on port 8000 and
> receive a text/plain HTTP response saying "Hello World!"? Never mind
> about the test for the moment.
> 
> And for #2, judicious placement of console output will help you figure
> out things you're not sure about. For instance, you're suspecting that
> the main thread is getting blocked handling the web server. Easy way
> to check:
> 
>     def setUp(self):
>         # Start the forecast server
>         self.server = ForecastServer()
>         self.server.start(webservice.app)
> 
> Just before you construct the server, print something out. After
> you've constructed it but before you call start(), print something
> out. And after starting it, print something out. Then run the program.
> If you see the first line and no other, then it's blocking during the
> construction. Other deductions I'm sure you can figure out.
> 
> One small point: Probe even things that you think are trivial. In the
> above example, I cannot see any reason why constructing
> ForecastServer() could possibly block, because its init does nothing
> but set a flag. But you can get surprised by things sometimes - maybe
> the problem is actually that you're not running the code you think you
> are, but there's some other ForecastServer kicking in, and it's
> synchronous rather than subprocess-based.
> 
> End-to-end testing is all very well, but when something goes wrong,
> the key is to break the program down into smaller parts. Otherwise,
> all you have is "it doesn't work", which is one of the most useless
> error reports ever. If someone comes to python-list saying "it doesn't
> work", we'll be asking him/her to give a lot more details; if your
> aunt asks you for help printing out a document because "it doesn't
> work", you'll probably have to go over and watch her attempt it; and
> it's the same with your test cases - you make them tell you more
> details.
> 
> Hope that helps! The techniques I'm offering are completely
> problem-independent, and even language-independent. IIDPIO debugging
> works in anything that gives you a console, which is pretty much
> everything - maybe it won't be print() but logging.debug(), but the
> same technique works.
> 
> ChrisA


Thanks for your comments Chris.

I've come back to the problem today after a few days on trip. Fortunately someone in other mailing list pointed me that the join method was hanging the main thread. Without this inconvenience I can focus on the exercise's main goal.

Despite the impression that surely I gave, I'm quite familiar with programming and general bug hunting rules. The problem is that I'm inexperienced with Python and the subtle details of multiple threads ;)

Thanks!

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


Thread

Noob in Python. Problem with fairly simple test case "Jason P." <suscricions@gmail.com> - 2015-07-15 04:44 -0700
  Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-15 22:11 +1000
    Re: Noob in Python. Problem with fairly simple test case Larry Hudson <orgnut@yahoo.com> - 2015-07-15 20:01 -0700
      Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-16 13:11 +1000
        Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-15 20:33 -0700
          Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-16 13:44 +1000
            Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 13:03 -0700
              Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 06:11 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 13:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Emile van Sebille <emile@fenx.com> - 2015-07-16 14:27 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 09:24 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 17:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 12:44 +1000
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 13:01 +1000
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 16:47 +1000
                Re: Noob in Python. Problem with fairly simple test case wxjmfauth@gmail.com - 2015-07-17 02:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 20:57 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 21:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 15:16 +1000
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 16:38 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-17 10:57 -0700
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-17 22:38 +0200
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-18 14:12 -0700
                Re: Noob in Python. Problem with fairly simple test case Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-17 23:03 +0100
                Re: Noob in Python. Problem with fairly simple test case Terry Reedy <tjreedy@udel.edu> - 2015-07-17 18:45 -0400
                Re: Noob in Python. Problem with fairly simple test case wxjmfauth@gmail.com - 2015-07-18 00:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-18 16:18 -0700
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-19 11:09 +0200
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-19 10:25 -0700
                Re: Noob in Python. Problem with fairly simple test case MRAB <python@mrabarnett.plus.com> - 2015-07-19 18:45 +0100
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-19 19:50 +0200
                Off-topic: Europe [was Re: Noob in Python. Problem with fairly simple test case] Steven D'Aprano <steve@pearwood.info> - 2015-07-20 12:30 +1000
                Re: Noob in Python. Problem with fairly simple test case Emile van Sebille <emile@fenx.com> - 2015-07-17 16:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-17 08:26 -0400
        Re: Noob in Python. Problem with fairly simple test case Larry Hudson <orgnut@yahoo.com> - 2015-07-16 20:49 -0700
    Re: Noob in Python. Problem with fairly simple test case "Jason P." <suscricions@gmail.com> - 2015-07-21 10:38 -0700
      Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-22 03:48 +1000

csiph-web