question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix for issue #129 makes freezing time in threads impossible

See original GitHub issue

I’m trying to test the interaction of several threads. In doing so, I need to freeze time, assert some things, tick, assert some more things, tick, etc. However, the fix for #129 appears to have made this impossible to do.

The problem is that I’m using time.time() in the code that I’m testing, and that code runs within multiple threads. As a result, the threading module appears in the stacktrace for my code that uses time.time(). So when _should_use_real_time inspects the stacktrace, it sees the threading frame and returns True, causing my code to get the real time. I had to do this to fix it:

def patched_freeze_time():
    f = freezegun.freeze_time()
    f.ignore = tuple(set(f.ignore) - {'threading'})
    return f

with patched_freeze_time() as frozen_time:
    # run tests

I understand the usefulness of ignoring threading by default, and I don’t want to regress #129, so I suggest a new freeze_time argument-with-default ignore_threading=True, and if it set to False then the threading module will not be included in ignore.

At alternative fix, if you feel that it’s truly necessary to always use real time in calls within the threading module itself, would be to hard-code exclude threading from the step where you patch modules’ imports, and then remove threading from the default ignores. In doing this, code calling time.time() (for example) within a running thread would still be affected by the frozen time, but time.time() calls within the threading module itself would not and would use real time.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
boxedcommented, Jul 20, 2019

I think we might need to think of more advanced/complex rules for looking at the stack. Not just saying “It’s threading!” but looking at why it’s in that module.

0reactions
westovercommented, Aug 13, 2019

Following

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matebook X Pro constantly freezing (event id 129) - Reddit
Now, the computer freezes ALL THE TIME, the disk usage goes up to 100% and any task that uses the disk is halted...
Read more >
Tomcat 7 Freeze after few days - Stack Overflow
The server is not loaded heavily, it's serving one request every 5 min or so. Is this some kind of ajp-thread leak issue?...
Read more >
Android 4.3: Bluetooth LE pretty instable [36976711]
I'm having similar issues - Nexus 5 running 4.4.2. Call discoverServices and receive callback to onServicesDiscovered. The status most of the time is...
Read more >
TM4C129XNCZAD: Invalid execution sequence - TI E2E
Part Number: TM4C129XNCZAD Other Parts Discussed in Thread: SEGGER , , DK-TM4C129X , EK-TM4C1294XL , EK-TM4C129EXL , MSP-EXP432E401Y , MSP432E401Y Hi, ...
Read more >
7 Problems to Look out for When Analyzing Garbage ...
When G1GC needs to do a full GC it spawns severl workers. If you have spare CPU capacity to run more threads, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found