A zc.monitor plugin for testing whether function hangs
Project description
A zc.monitor plugin for testing whether function hangs
Somtimes, computation stops and it can be hard to find out why. Tools like strace can be helpful, but are very low level. If a call hangs calling external network services, all you might see is a select or poll call and not what serveice was being called.
Isithanging provides a simple registry and a helper function for registering and unregistering calls. To illustrate how this, we’ll use a test function that blocks until we unblock it by setting an event:
>>> import zc.isithanging.tests >>> event, blocker = zc.isithanging.tests.create_blocker()
The blocker function just returns any arguments it was passed.
To check whether a function is blocking, we use zc.isinhanging.run to run the function. We’ll do so here in a thread:
>>> import zc.thread >>> @zc.thread.Thread ... def thread(): ... print zc.isithanging.run(blocker, 1, foo=2)
There’s also a decorator that takes wraps a function and takes care of calling run.
Let’s create seome more jobs:
>>> e1, b1 = zc.isithanging.tests.create_blocker() >>> suspect = zc.isithanging.suspect(b1) >>> @zc.thread.Thread ... def t1(): ... print suspect(1)
Above, we used the suspect decorator as a function (rather than with decorator syntax.)
>>> e2, b2 = zc.isithanging.tests.create_blocker() >>> @zc.thread.Thread ... def t2(): ... print zc.isithanging.run(b2, 2)
We can see what’s running by looking at zc.isithanging.running:
>>> now = time.time() >>> for r in zc.isithanging.running: ... print r.show(now) Sun Nov 16 09:48:29 2014 1s <function f at 0x10251e500> (1,) {'foo': 2} Sun Nov 16 09:48:29 2014 1s <function f at 0x10251e9b0> (1,) {} Sun Nov 16 09:48:29 2014 1s <function f at 0x10251eb18> (2,) {}
The show function shows start time, elapsed time in seconds, function and arguments.
When a job stops, it’s automatically unregistered:
>>> e1.set(); t1.join() ((1,), {})>>> for r in zc.isithanging.running: ... print r Sun Nov 16 09:48:29 2014 2s <function f at 0x102d1e500> (1,) {'foo': 2} Sun Nov 16 09:48:29 2014 2s <function f at 0x102d1eb18> (2,) {}
There’s a zc.monitor command that prints the jobs:
>>> import sys >>> zc.isithanging.isithanging(sys.stdout) Sun Nov 16 09:48:29 2014 2s <function f at 0x102d1e500> (1,) {'foo': 2} Sun Nov 16 09:48:29 2014 2s <function f at 0x102d1eb18> (2,) {}
Let’s finish the jobs and try again:
>>> event.set(); thread.join() ((1,), {'foo': 2}) >>> e2.set(); t2.join() ((2,), {})>>> zc.isithanging.isithanging(sys.stdout)
Changes
0.3.0 (2014-11-17)
Added a “suspect” decorator to decorate functions suspected of hanging.
0.2.0 (2014-11-17)
(Accidental re-release of 0.1.)
0.1.0 (2014-11-17)
Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file zc.isithanging-0.3.0.tar.gz
.
File metadata
- Download URL: zc.isithanging-0.3.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d71e72345a5ed54413c1cde6a158e11c6b905d385a2cd1adcb1a0a56a2f1dae |
|
MD5 | 73553570ffa9bcb8409820b9a104001a |
|
BLAKE2b-256 | ef99b4e977851ed59e48010502dd6ad7b42fb24a0ace9538ed4196cb2fbe748d |