Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'debugging': 0.07; 'error:': 0.07; '__init__': 0.09; 'constructor': 0.09; 'function:': 0.09; 'method,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'thread': 0.14; 'callable': 0.16; 'called,': 0.16; 'called.': 0.16; 'chris,': 0.16; 'helps!': 0.16; 'parentheses': 0.16; 'stats': 0.16; 'subject:Thread': 0.16; 'typeerror:': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'import': 0.22; '(in': 0.22; 'email addr:gmail.com>': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; '>': 0.26; 'skip:" 30': 0.26; 'this:': 0.26; 'second': 0.26; 'pass': 0.26; 'skip:_ 20': 0.27; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'chris': 0.29; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; '(which': 0.31; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'another.': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'up.': 0.33; 'url:python': 0.33; '(most': 0.33; 'skip:_ 10': 0.34; 'basic': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'returning': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'skip:4 10': 0.37; 'two': 0.37; 'sometimes': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'recent': 0.39; 'skip:& 20': 0.39; 'does': 0.39; 'unable': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'url:mail': 0.40; 'even': 0.60; 'removing': 0.60; 'hope': 0.61; 'skip:* 10': 0.61; 'simply': 0.61; 'first': 0.61; "you'll": 0.62; 'such': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'techniques': 0.66; '2015': 0.84; 'end.': 0.84; 'hardly': 0.84; 'self.run()': 0.84; 'subject::': 0.85; 'reply,': 0.93; 'incredibly': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ljurfYsudWjMAJH7eyQQBMJHICYyqEjmcHX2MHiL5bo=; b=LYUd542wAAWJPOqkN8zWhQlj6bVq9y/0VHKKvBuOacmgdK+TWCiurBE64iZjTKM+FR /LqYyQ26ObMBf8CctL03BFCpaDFe8WdnN6LPu5rjI5lRNzFhtLKL67XqZAEu550Rx2M8 LgVaVI+QCuRV/6xaGBXTqs200jMAZq2P4UnY+8KDEu3iKsE1yhw5nanRR1UfHU1Lcsmv B9qh4Ixqbce4yVgr6pqXNl1qqy/IIULCgybeNctiRNfz6RPOE2t5BHz1gXX8hZGHCKJc K8IDiqTFOG34EEc8vuUBOOBQhwHRgX+qS1bK7BnPoEAhyP2qvVI2ce4sLAa1e7NDYwck Vrhg== MIME-Version: 1.0 X-Received: by 10.50.221.98 with SMTP id qd2mr1253095igc.37.1430825797107; Tue, 05 May 2015 04:36:37 -0700 (PDT) In-Reply-To: References: Date: Tue, 5 May 2015 16:36:37 +0500 Subject: Re: Exception in thread Thread-4: From: david jhon To: Chris Angelico Cc: "python-list@python.org" Content-Type: multipart/alternative; boundary=001a11347f205f455f05155417f1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 165 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430825801 news.xs4all.nl 2856 [2001:888:2000:d::a6]:44625 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 10606 X-Received-Body-CRC: 1333047273 Xref: csiph.com comp.lang.python:89961 --001a11347f205f455f05155417f1 Content-Type: text/plain; charset=UTF-8 Hi Chris, Thanks a lot for such a comprehensive reply, I got it fixed now. Thanks again :) On Tue, May 5, 2015 at 2:52 PM, Chris Angelico wrote: > On Tue, May 5, 2015 at 7:23 PM, david jhon wrote: > > from threading import Timer, Lock > > > > class miTestClass(EventMixin): > > def __init__(self, t, r, bw): > > self.statMonitorLock = Lock() #to lock the multi access threads > > self.statMonitorLock.acquire() > > statMonitorTimer = Timer(10.0, self._collectFlowStats()) #timer > to > > collect stats > > statMonitorTimer.start() > > > > but I am getting following error: > > > > Exception in thread Thread-4: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.7/threading.py", line 1082, in run > > self.function(*self.args, **self.kwargs) > > TypeError: 'NoneType' object is not callable > > The Timer() class will call a function when it's ready. To use that, > you want to pass it a function. Try putting these two lines of code > into your __init__ function: > > print(self._collectFlowStats) > print(self._collectFlowStats()) > > (Aside: This is something I like to call "IIDPIO debugging": If In > Doubt, Print It Out. You sometimes have more sophisticated debugging > techniques available, but you hardly ever are unable to basic 'print', > in some form or another. It's incredibly useful.) > > The first one will print out something like this: > > object at 0x12345678>> > > The second will actually call that function (which may or may not do > anything visible), and then print out: > > None > > If you change your _collectFlowStats function a bit, you can see even > more of what's happening. Something like this: > > def _collectFlowStats(self): > print("_collectFlowStats has been called. Returning 42...") > return 42 > > Then you'll see that it gets called, and does its print, and then 42 > gets printed out at the end. > > In your case, simply removing the parentheses from > self._collectFlowStats should do what you want - the Timer constructor > will be passed a function (in this case, a bound method, but same > same), and that function won't be called until the timer is up. > > Hope that helps! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > --001a11347f205f455f05155417f1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Chris,

Thanks a lot for such a compr= ehensive reply, I got it fixed now. Thanks again :)

On Tue, May 5, 2015 at 2:52 PM,= Chris Angelico <rosuav@gmail.com> wrote:
On Tue, May 5, 2015 at 7:23 PM, david jhon = <djhon9813@gmail.com> wrot= e:
> from threading import Timer, Lock
>
> class miTestClass(EventMixin):
>=C2=A0 =C2=A0 =C2=A0def __init__(self, t, r, bw):
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.statMonitorLock =3D Lock() #to = lock the multi access threads
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.statMonitorLock.acquire()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statMonitorTimer =3D Timer(10.0, sel= f._collectFlowStats()) #timer to
> collect stats
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statMonitorTimer.start()
>
> but I am getting following error:
>
> Exception in thread Thread-4:
> Traceback (most recent call last):
>=C2=A0 =C2=A0File "/usr/lib/python2.7/threading.py", line 810= , in __bootstrap_inner
>=C2=A0 =C2=A0 =C2=A0self.run()
>=C2=A0 =C2=A0File "/usr/lib/python2.7/threading.py", line 108= 2, in run
>=C2=A0 =C2=A0 =C2=A0self.function(*self.args, **self.kwargs)
> TypeError: 'NoneType' object is not callable

The Timer() class will call a function when it's ready. To use t= hat,
you want to pass it a function. Try putting these two lines of code
into your __init__ function:

print(self._collectFlowStats)
print(self._collectFlowStats())

(Aside: This is something I like to call "IIDPIO debugging": If I= n
Doubt, Print It Out. You sometimes have more sophisticated debugging
techniques available, but you hardly ever are unable to basic 'print= 9;,
in some form or another. It's incredibly useful.)

The first one will print out something like this:

<bound method miTestClass._collectFlowStats of <__main__.miTestClass<= br> object at 0x12345678>>

The second will actually call that function (which may or may not do
anything visible), and then print out:

None

If you change your _collectFlowStats function a bit, you can see even
more of what's happening. Something like this:

def _collectFlowStats(self):
=C2=A0 =C2=A0 print("_collectFlowStats has been called. Returning 42..= .")
=C2=A0 =C2=A0 return 42

Then you'll see that it gets called, and does its print, and then 42 gets printed out at the end.

In your case, simply removing the parentheses from
self._collectFlowStats should do what you want - the Timer constructor
will be passed a function (in this case, a bound method, but same
same), and that function won't be called until the timer is up.

Hope that helps!

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list

--001a11347f205f455f05155417f1--