N =50info =Nonefor i in (tracker := track2(range(N), total=N)): time.sleep(0.01) info =f"My Info: {i*3.122:.2f}"if i == N //2:print()if i >= N //2: tracker.send(info)
@io(level="trace")def foo(a, b=None):if b isNone:return a +1else: time.sleep(2)return a + bwith trace_mode(): foo(10)import time time.sleep(1) foo(10, b=20)
Source path:... <ipython-input-1-57a17d8aa123>Starting var:.. a = 10Starting var:.. b = None
18:58:59.237764 call 1 SOURCE IS UNAVAILABLE
18:58:59.237840 line 3 SOURCE IS UNAVAILABLE
18:58:59.237855 line 4 SOURCE IS UNAVAILABLE
18:58:59.237865 return 4 SOURCE IS UNAVAILABLE
Return value:.. 11Elapsed time: 00:00:00.000309Source path:... <ipython-input-1-57a17d8aa123>Starting var:.. a = 10Starting var:.. b = 20
18:59:00.636968 call 1 SOURCE IS UNAVAILABLE
18:59:00.637033 line 3 SOURCE IS UNAVAILABLE
18:59:00.637046 line 6 SOURCE IS UNAVAILABLE
18:59:02.642140 line 7 SOURCE IS UNAVAILABLE
18:59:02.642571 return 7 SOURCE IS UNAVAILABLE
Return value:.. 30Elapsed time: 00:00:02.006072
Try Catch with a single line
@tryydef do(a, b, c):return1/0x = do(1, 2, c=10)assert x isNone# tryy returns None by default
[01/02/25 20:59:38] WARNING Error for `do`: ZeroDivisionError: division by zero 579939537.py:wrapper:27
WARNING Error for `do`: 579939537.py:wrapper:32 Traceback (most recent call last): File "/var/folders/1_/71dqv9vx2750gmyz77q_f45w0000gn/T/ipykernel_70802/579939537.py", line 22, in wrapper return f(*args, **kwargs) ^^^^^^^^^^^^^^^^^^ File "/var/folders/1_/71dqv9vx2750gmyz77q_f45w0000gn/T/ipykernel_70802/580638143.py", line 3, in do return 1/0 ~~^~~ ZeroDivisionError: division by zero
There’s onlly one usecase where you would want to send in a list by yourself - when you want to append your errors to an existing list. The sensible default is to always store the errors, especially because this is a debugging tool.
Finally, you want to run the function (without try) to reproduce the error and actually start debugging. Just use the .F attribute to access the original function that you created
ix =2data = do.error_store[ix]try: do.F(*data.args, **data.kwargs)exceptExceptionas e:print(f"ERROR: ", e)