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


Groups > comp.lang.python > #74665

Re: Blocked thread

References (1 earlier) <CAPTjJmpi8d28ahbba0LNQU8rY4r0EvwUmDS2zRMVsUn0tubtuQ@mail.gmail.com> <CANc-5UyPjdozTKjOzOy6H=Ar3_Jzx1MU68qymyEoFWx7p_piEQ@mail.gmail.com> <CACwCsY54hxnRHainr7Mk6T=tEosTC2ja-pk7=_6QL11MKsD3+g@mail.gmail.com> <CAPTjJmrapq_bLOEYcwh3+MTrb1JCyUxJYuHrN2Vkd+aU9N12=A@mail.gmail.com> <CACwCsY7rjermm=NJCB8sVCjnppFOst3v7pFcss_PwTKaV7nfHg@mail.gmail.com>
Date 2014-07-18 04:19 +1000
Subject Re: Blocked thread
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.11944.1405621159.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jul 18, 2014 at 4:13 AM, Larry Martell <larry.martell@gmail.com> wrote:
> But every once it a while it takes 2 minutes. It will be hard
> to detect that manually. What I was trying to do in my threaded code
> was detect when it was taking more than 5 seconds, and then start
> monitoring it.

Fair enough. In that case, I'd just do it the simple way: get the
backend PID (or whatever other connection identification is
appropriate), spin off a thread/process to do the monitoring. It
sleeps five seconds, then does its first query. If the server says
that connection's done its work, easy! Disconnect, job done.
Otherwise, do whatever monitoring you can.

But if your main goal is diagnosis, rather than monitoring, here's a
really really naughty idea that might help: Refrain from committing if
it's taken too long. Something like this:

start = time.time()
# do the actual work, but don't commit
if time.time() > start + 5:
    # raise an alarm, tell a human being that something's wrong
else:
    commit()

Obviously you run this "dangeroussed-up version" of the script only
when there's a person there to react to the alarm, otherwise you go
for the normal one. But this could give you a massive insight into
what's happening, because until you commit, you have all your locks
and things.

ChrisA

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


Thread

Re: Blocked thread Chris Angelico <rosuav@gmail.com> - 2014-07-18 04:19 +1000

csiph-web