Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception raise ZeroDivisionError #100

Closed
MadRabbit05 opened this issue Sep 22, 2021 · 7 comments · Fixed by #123
Closed

Exception raise ZeroDivisionError #100

MadRabbit05 opened this issue Sep 22, 2021 · 7 comments · Fixed by #123
Assignees
Labels
bug Something isn't working

Comments

@MadRabbit05
Copy link

Hi,

Exception is raised if profiled function do nothing (just pass). I agree that function useless should not be present or profile.
But if you decide to profile in a single shoot a lot of functions, some stub function may be present in package.

File "/opt/anaconda3/envs/XXXXXX/lib/python3.8/site-packages/line_profiler.py", line 228, in show_func
    '%5.1f' % (100 * time / total_time) )
ZeroDivisionError: float division by zero

with that part of code :

from line_profiler import LineProfiler
lprofiler = LineProfiler()

for function in functions:
    lprofiler.add_function(fonction)

lp_wrapper = lprofiler(mainProfile)
lp_wrapper()

lprofiler.print_stats()

Thanks for that package :-)
MadRabbit

@Erotemic Erotemic added the bug Something isn't working label Sep 22, 2021
@Erotemic Erotemic self-assigned this Sep 24, 2021
@Nodd
Copy link
Contributor

Nodd commented Feb 9, 2022

I can't reproduce this bug. Can you provide an example of a function that does nothing, and which OS ou use ? I tried :

@profile
def dummy1():
    pass

@profile
def dummy2():
    """docstring"""

@profile
def dummy3():
    return

But all of them give me non-zero time for the last line. I tried on Windows with python3.9.

@Nodd
Copy link
Contributor

Nodd commented Feb 12, 2022

Update: I got the problem while running tests in Linux in Nodd/lineprofilergui@09ed262. Maybe it has something to do with timer precision.
Anyway, it needs fixing, either by displaying NaN or an empty value.

@Erotemic
Copy link
Member

@Nodd Can you make a PR with logic to handle this case?

@Nodd
Copy link
Contributor

Nodd commented Feb 13, 2022

Sure, that was my intention.
Which solution do you prefer, display a NaN or an empty string instead of the percent value ?

@MadRabbit05
Copy link
Author

Sorry for the delay, Nodd.
What about setting variable "percent" to zero ?

if self.total_time is None:
    return ""
if self._func_data.total_time == 0:
    return f"0.0"
.....

@Erotemic
Copy link
Member

I would personally go for NaN, but either solution sounds fine to me.

@MadRabbit05
Copy link
Author

percent=0 stands for "function ran in 0% of total_time".
Function ran in eps seconds so the percent computed is total_time/eps (so egal to 0 with the rounding format)

NaN could be more for "profiled function" unused in code (I do not know if it is possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants