how does Python get the time()?
by Skaperen from LinuxQuestions.org on (#55EPQ)
i put together this short script in Python:
Code:import time
for _ in range(8):
print(int(time.time()*3906250))then i ran it on Xubuntu 18.04 on Python 3.6 under strace and got:
Code:...
stat("tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
openat(AT_FDCWD, "tt.py", O_RDONLY) = 3
ioctl(3, FIOCLEX) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
lseek(3, 0, SEEK_SET) = 0
read(3, "import time\nfor _ in range(8):\n "..., 45) = 45
read(3, "time.time()*3906250))\n", 4096) = 22
close(3) = 0
stat("tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
readlink("tt.py", 0x7fff6a7bced0, 4096) = -1 EINVAL (Invalid argument)
getcwd("/home/forums", 4096) = 13
lstat("/home/forums/tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
openat(AT_FDCWD, "tt.py", O_RDONLY) = 3
fcntl(3, F_GETFD) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
ioctl(3, TCGETS, 0x7fff6a7cde50) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
read(3, "import time\nfor _ in range(8):\n "..., 4096) = 67
lseek(3, 0, SEEK_SET) = 0
brk(0x29b5000) = 0x29b5000
read(3, "import time\nfor _ in range(8):\n "..., 4096) = 67
read(3, "", 4096) = 0
brk(0x29ac000) = 0x29ac000
brk(0x29aa000) = 0x29aa000
close(3) = 0
openat(AT_FDCWD, "/usr/share/zoneinfo/America/New_York", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3545, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=3545, ...}) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 3545
lseek(3, -2261, SEEK_CUR) = 1284
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 2261
close(3) = 0
write(1, "6226917864829328\n", 176226917864829328
) = 17
write(1, "6226917864829508\n", 176226917864829508
) = 17
write(1, "6226917864829629\n", 176226917864829629
) = 17
write(1, "6226917864829744\n", 176226917864829744
) = 17
write(1, "6226917864829858\n", 176226917864829858
) = 17
write(1, "6226917864829970\n", 176226917864829970
) = 17
write(1, "6226917864830081\n", 176226917864830081
) = 17
write(1, "6226917864830191\n", 176226917864830191
) = 17
brk(0x29a8000) = 0x29a8000
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f81e9921f20}, {sa_handler=0x62ffc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f81e9921f20}, 8) = 0
sigaltstack(NULL, {ss_sp=0x28db540, ss_flags=0, ss_size=8192}) = 0
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}, NULL) = 0
exit_group(0) = ?
+++ exited with 0 +++
lt2a/forums /home/forums 27> cat tt.py
import time
for _ in range(8):
print(int(time.time()*3906250))
lt2a/forums /home/forums 28>it looks like no syscall is needed to get the time. what C library call can do that? or is it just a special memory access location?


Code:import time
for _ in range(8):
print(int(time.time()*3906250))then i ran it on Xubuntu 18.04 on Python 3.6 under strace and got:
Code:...
stat("tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
openat(AT_FDCWD, "tt.py", O_RDONLY) = 3
ioctl(3, FIOCLEX) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
lseek(3, 0, SEEK_SET) = 0
read(3, "import time\nfor _ in range(8):\n "..., 45) = 45
read(3, "time.time()*3906250))\n", 4096) = 22
close(3) = 0
stat("tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
readlink("tt.py", 0x7fff6a7bced0, 4096) = -1 EINVAL (Invalid argument)
getcwd("/home/forums", 4096) = 13
lstat("/home/forums/tt.py", {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
openat(AT_FDCWD, "tt.py", O_RDONLY) = 3
fcntl(3, F_GETFD) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
ioctl(3, TCGETS, 0x7fff6a7cde50) = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=67, ...}) = 0
read(3, "import time\nfor _ in range(8):\n "..., 4096) = 67
lseek(3, 0, SEEK_SET) = 0
brk(0x29b5000) = 0x29b5000
read(3, "import time\nfor _ in range(8):\n "..., 4096) = 67
read(3, "", 4096) = 0
brk(0x29ac000) = 0x29ac000
brk(0x29aa000) = 0x29aa000
close(3) = 0
openat(AT_FDCWD, "/usr/share/zoneinfo/America/New_York", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=3545, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=3545, ...}) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 3545
lseek(3, -2261, SEEK_CUR) = 1284
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 2261
close(3) = 0
write(1, "6226917864829328\n", 176226917864829328
) = 17
write(1, "6226917864829508\n", 176226917864829508
) = 17
write(1, "6226917864829629\n", 176226917864829629
) = 17
write(1, "6226917864829744\n", 176226917864829744
) = 17
write(1, "6226917864829858\n", 176226917864829858
) = 17
write(1, "6226917864829970\n", 176226917864829970
) = 17
write(1, "6226917864830081\n", 176226917864830081
) = 17
write(1, "6226917864830191\n", 176226917864830191
) = 17
brk(0x29a8000) = 0x29a8000
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f81e9921f20}, {sa_handler=0x62ffc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f81e9921f20}, 8) = 0
sigaltstack(NULL, {ss_sp=0x28db540, ss_flags=0, ss_size=8192}) = 0
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}, NULL) = 0
exit_group(0) = ?
+++ exited with 0 +++
lt2a/forums /home/forums 27> cat tt.py
import time
for _ in range(8):
print(int(time.time()*3906250))
lt2a/forums /home/forums 28>it looks like no syscall is needed to get the time. what C library call can do that? or is it just a special memory access location?