Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89953
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*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; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 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; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; '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; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 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; '(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; 'should': 0.36; 'two': 0.37; 'sometimes': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'recent': 0.39; 'does': 0.39; 'unable': 0.39; 'skip:p 20': 0.39; 'called': 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; 'more': 0.64; 'techniques': 0.66; '2015': 0.84; 'end.': 0.84; 'hardly': 0.84; 'self.run()': 0.84; 'subject::': 0.85; 'to:none': 0.92; '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:cc :content-type; bh=U7C5rHz/UnXNxrQR1p0QkSwFq78d9UXIlMIEK74Dlkg=; b=LOnePRaIrYf19B8TZfeJ3e5gpE+bQ3TiXG/BTbLkuQs3dAg59CZ75/1SiKghLL1t2a JAr4VGg8PSQb/nakyhiuZxrQf7XjqNAePWKYAhqpCoJloxfDH1eTYKFf7OxEW6KZXSZ9 REWegKRrGs5ZA/Dl1bOlqeBaR3r/7UjRBCXia2i8bgp2Wq+6j75bm8Abqt/3UL4i/7k9 W7K38PFfLtT5KlybccAYhlwPA6DJyKV8lzElMagTPrpB4ttrYDHHnCZa8LupA+e+UBgf RVCNalAPqqmf05UPnFEg3av/7d/f+6x/eLIknO3TihNUEmeWhrLW30aWmzzTJ1EMgAWO VhdQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.108.115 with SMTP id hj19mr940852igb.34.1430819530298; Tue, 05 May 2015 02:52:10 -0700 (PDT) |
| In-Reply-To | <CANPUzQ0MUXpv+ctMzZ6AeAvm6L4gatc7eTq=PmvU=opy+Np6mw@mail.gmail.com> |
| References | <CANPUzQ0MUXpv+ctMzZ6AeAvm6L4gatc7eTq=PmvU=opy+Np6mw@mail.gmail.com> |
| Date | Tue, 5 May 2015 19:52:10 +1000 |
| Subject | Re: Exception in thread Thread-4: |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.119.1430819533.12865.python-list@python.org> (permalink) |
| Lines | 61 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430819533 news.xs4all.nl 2872 [2001:888:2000:d::a6]:36722 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89953 |
Show key headers only | View raw
On Tue, May 5, 2015 at 7:23 PM, david jhon <djhon9813@gmail.com> 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:
<bound method miTestClass._collectFlowStats of <__main__.miTestClass
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Exception in thread Thread-4: Chris Angelico <rosuav@gmail.com> - 2015-05-05 19:52 +1000
csiph-web