2017-10-31 15:54:39 +00:00
|
|
|
Miscellanea
|
|
|
|
-----------
|
|
|
|
|
|
|
|
.. function:: pydu.unix_timeout(seconds)
|
|
|
|
|
|
|
|
This func decorates any func which may be hang for a while. The param ``seconds``
|
2017-11-03 14:31:03 +00:00
|
|
|
should be integer.
|
2017-10-31 15:54:39 +00:00
|
|
|
In `test.py`, you may write like below:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
import time
|
|
|
|
from pydu.misc import unix_timeout
|
|
|
|
@unix_timeout(1)
|
|
|
|
def f():
|
|
|
|
time.sleep(1.01)
|
|
|
|
f()
|
|
|
|
|
2017-11-01 15:13:21 +00:00
|
|
|
And run `test.py`, will see ``TimeoutError``.
|
2017-10-31 15:54:39 +00:00
|
|
|
|
2017-11-03 14:31:03 +00:00
|
|
|
.. note:: ``unix_timeout`` can only be used on ``unix-like`` system.
|
|
|
|
|
2017-10-31 15:54:39 +00:00
|
|
|
|
|
|
|
.. function:: pydu.trace(obj)
|
|
|
|
|
|
|
|
Tracing every statement and line number for running program, like ``bash -x``.
|
|
|
|
In `test.py`, you may write like below:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
from pydu import trace
|
|
|
|
@trace
|
|
|
|
def f():
|
|
|
|
print(1)
|
|
|
|
a = 1 + 5
|
|
|
|
b = [a]
|
|
|
|
print(2)
|
|
|
|
f()
|
|
|
|
|
2017-11-01 15:13:21 +00:00
|
|
|
And run `test.py`, will see below output from console:
|
2017-10-31 15:54:39 +00:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
test.py(4): print(1)
|
|
|
|
1
|
|
|
|
test.py(5): a = 1 + 5
|
|
|
|
test.py(6): b = [a]
|
|
|
|
test.py(7): print(2)
|
|
|
|
2
|