Skip to content

bpo-31784: Use time.time_ns() in uuid.uuid1()#11189

Merged
vstinner merged 2 commits intopython:masterfrom
vstinner:uuid_time_ns
Dec 18, 2018
Merged

bpo-31784: Use time.time_ns() in uuid.uuid1()#11189
vstinner merged 2 commits intopython:masterfrom
vstinner:uuid_time_ns

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Dec 17, 2018

Replace int(time.time() * 1e9) with time.time_ns().

https://bugs.python.org/issue31784

uuid.uuid1() now calls time.time_ns() rather than
int(time.time() * 1e9).

Replace also int(nanoseconds/100) with nanoseconds // 100.
@vstinner vstinner requested review from taleinat and warsaw December 17, 2018 10:50
Comment thread Lib/uuid.py
global _last_timestamp
import time
nanoseconds = int(time.time() * 1e9)
nanoseconds = time.time_ns()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why int(time.time() * 1e9) == time.time_ns() is False? Must be True, isn't?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.time_ns() == time.time_ns() is false because clock changes each time you call it :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ho! you are right, I was confused

@vstinner
Copy link
Copy Markdown
Member Author

I added an unit test, but I'm not sure if it's worth it?

@vstinner vstinner merged commit 62a68b7 into python:master Dec 18, 2018
@vstinner vstinner deleted the uuid_time_ns branch December 18, 2018 10:45
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

Successfully merging this pull request may close these issues.

4 participants