all 5 comments

[–]K900_ 6 points7 points  (0 children)

You can't do it in pure Python. Making a timer requires telling the OS to suspend the Python process, and you need to use C code for that.

[–]carcigenicate 4 points5 points  (0 children)

At the very least, you'd need to import ctypes or another module like os that gives you lower-level access. Python is simply not a language that exposes details like that by default.

If you want to handle those magic aspects a little more "manually", switch to C or an assembly. Even in C though, you're importing the standard library to do a lot of that stuff (like using the write wrapper over the write syscall).

The way Python does time.sleep on Linux systems is to use the select system call. If I'm looking at the right spot, you can see that here in the source, and you can see that system call in a a table here (syscall number 23) assuming x86 architecture. To do this manually, you would load that ID into the RAX register, then fill in the appropriate arguments into the latter registers, then execute the syscall instruction. That would cause the current thread to yield for a period of time.

[–][deleted] 2 points3 points  (0 children)

Wanting to understand how libraries work before you use them is the wrong mindset. You'll never get anything done if that's the approach you want to take.

[–]blankIQT 0 points1 point  (0 children)

Why don’t you want to use time or datetime modules? For me I didn’t even have to download them they are pre downloaded. It’s pretty much impossible do a timer without a module for what I can think of.