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

relative_time fails with generator #182

Open
cool-RR opened this issue May 4, 2020 · 5 comments
Open

relative_time fails with generator #182

cool-RR opened this issue May 4, 2020 · 5 comments

Comments

@cool-RR
Copy link
Owner

cool-RR commented May 4, 2020

I found a bug with relative_time when used with a generator. The times shown seem to be reset at some point. I don't know whether this bug could also happen without generators.

@iory Can you take a look at this bug?

@alexmojaki I suspect that this has something to do with the start_times dict you suggested.

Sample:

import pysnooper
import time

def g():
    time.sleep(0.1)
    yield 8
    time.sleep(0.1)

@pysnooper.snoop(relative_time=True)
def f():
    time.sleep(0.1)
    yield from g()
    time.sleep(0.1)


tuple(f())

Output:

Source path:... C:\Users\Administrator\Desktop\fuck.py
00:00:00.000000 call        10 def f():
00:00:00.000000 line        11     time.sleep(0.1)
00:00:00.100000 line        12     yield from g()
00:00:00.200000 return      12     yield from g()
Return value:.. 8
Elapsed time: 00:00:00.200000
00:00:00.000000 call        12     yield from g()
00:00:00.100000 exception   12     yield from g()
StopIteration
00:00:00.100000 line        13     time.sleep(0.1)
00:00:00.207002 return      13     time.sleep(0.1)
Return value:.. None
Elapsed time: 00:00:00.207002
@alexmojaki
Copy link
Collaborator

Well I see a call in the middle, so I think that's just how PySnooper interprets generators resuming execution, like what I mentioned here: https://github.com/alexmojaki/snoop/wiki/Comparison-to-PySnooper#generators

@cool-RR
Copy link
Owner Author

cool-RR commented May 4, 2020

Hmm, interesting. Do you think that if I were to cherry-pick that feature out of snoop, this bug would be solved without any changes to the start_times logic?

@alexmojaki
Copy link
Collaborator

I don't think it would be that simple, but I think the process of extracting that feature would probably make it pretty easy to understand and fix this bug.

I'm guessing the reset happens here https://github.com/cool-RR/PySnooper/blob/master/pysnooper/tracer.py#L381

@cool-RR
Copy link
Owner Author

cool-RR commented May 4, 2020 via email

@cool-RR cool-RR self-assigned this May 4, 2020
@cool-RR
Copy link
Owner Author

cool-RR commented May 22, 2020

God damn it, this is complicated.

I made a failing test, but figuring out how to fix the behavior is hard. @iory , @alexmojaki if any of you could be interested in trying this bug, feel free.

@cool-RR cool-RR removed their assignment May 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants