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

Using freezegun during threaded function causes an odd error #503

Open
datacubed opened this issue May 11, 2023 · 6 comments
Open

Using freezegun during threaded function causes an odd error #503

datacubed opened this issue May 11, 2023 · 6 comments

Comments

@datacubed
Copy link

datacubed commented May 11, 2023

with freeze_time('2023-01-01 12:00:00+00:00'):
    my_model.value += 1
    my_model.save(update_fields=['value'])

I get this error: "'_freeze_time' object has no attribute 'fake_names'"

And this stacktrace:

my_model.save(update_fields=['value'])
  File "/usr/local/lib/python3.8/dist-packages/freezegun/api.py", line 616, in __exit__
    self.stop()
  File "/usr/local/lib/python3.8/dist-packages/freezegun/api.py", line 741, in stop
    if module_attribute in self.fake_names:

Looking at the code it seems like self.fake_names is never populated, and maybe that start() is not called?

@markddavidoff
Copy link

+1 also having this issue.

@pnajman-modoolar
Copy link

+1 I have this issue as well.

@markddavidoff
Copy link

I ended up adding a setup sync step in my test code, where each thread does a serialized setup before being used for concurrent test code.

@pnajman-modoolar
Copy link

@markddavidoff

I'm afraid I don't understand what you mean by that.

@markddavidoff
Copy link

You can create a wrapper function when freezing time in threads which wraps the freeze time call with a lock instead of calling freeze time directly. This force your threads to only freeze time one at a time.

@mangelozzi
Copy link

You can create a wrapper function when freezing time in threads which wraps the freeze time call with a lock instead of calling freeze time directly. This force your threads to only freeze time one at a time.

Could you please share a code snippet demonstrating your fix?

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

4 participants