bpo-31784: Use time.time_ns() in uuid.uuid1() by vstinner · Pull Request #11189 · python/cpython

@vstinner

@vstinner

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

Replace also int(nanoseconds/100) with nanoseconds // 100.

@vstinner

eamanu

global _last_timestamp
import time
nanoseconds = int(time.time() * 1e9)
nanoseconds = time.time_ns()

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?

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 :-)

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

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