Created
October 16, 2018 22:27
-
-
Save beaugunderson/68ea6424a4fdcf763ccad08e42a74974 to your computer and use it in GitHub Desktop.
timedelta / cProfile repro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
working: -25200 | |
broken: no exception | |
broken: 2177280001.000001 | |
*** PROFILER RESULTS *** | |
broken (repro.py:18) | |
function called 1 times | |
5 function calls in 0.000 seconds | |
Ordered by: cumulative time, internal time, call count | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.000 0.000 0.000 0.000 repro.py:18(broken) | |
2 0.000 0.000 0.000 0.000 {built-in method builtins.print} | |
1 0.000 0.000 0.000 0.000 {built-in method total_seconds} | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
0 0.000 0.000 profile:0(profiler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
from profilehooks import profile | |
# is this a silly thing to do? maybe, but dateutil does so: | |
# https://github.com/dateutil/dateutil/blob/5128426b52543faef00617125b4a977343fe0664/dateutil/tz/tz.py#L1050 | |
total_seconds = getattr(timedelta, 'total_seconds') | |
def working(offset): | |
# this is a simplified version of dateutil.tz.tzoffset.__init__() | |
try: | |
value = total_seconds(offset) | |
print('working: no exception') | |
except: | |
value = offset | |
print('working:', value) | |
@profile | |
def broken(offset): | |
try: | |
value = total_seconds(offset) | |
print('broken: no exception') | |
except: | |
value = offset | |
print('broken:', value) | |
if __name__ == '__main__': | |
working(-25200) | |
broken(-25200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment