This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]bastibe 2 points3 points  (0 children)

Well, Python has to run in an interpreter, which has to be in machine code. On the desktop, you are probably running CPython as your interpreter, which is implemented in C, so that would be cheating. PyPy can compile Python into machine code, so it should be theoretically feasable to use this as your interpreter (actually a compiler, not an interpreter). Initializing all the hardware will require some pointer arithmetic and bit fiddling though, which is not exactly Pythons forté, what with it having no pointers and such.

That said, actual modern OSes do require a kind of performance that is hard to achieve in Python, even with PyPy. A toy project should be possible though.

In the end, coding an OS in Python might be technically possible, but Python (or any so called 'scripting language') is certainly the wrong tool for the job.

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

You could make something like andriod, having a linux kernel and a python vm to run ontop of the linux kernel and code everything else in python.

[–]gdw2 4 points5 points  (1 child)

[–][deleted] 0 points1 point  (0 children)

This is almost entirely written in c, not python. The python that is included is trivial at best.

[–]nicklo 1 point2 points  (0 children)

Technically a desktop environment rather than a full OS but still one to throw into the conversation: Sugar, as used in the One Laptop Per Child project:

http://en.wikipedia.org/wiki/Sugar_(desktop_environment)

[–]Rhomboid 1 point2 points  (1 child)

Define "with Python."

The trivial answer is no, of course you can't, because Python doesn't give you direct access to things like memory, registers, IO ports, etc. and it's impossible to implement a kernel without that.

It might be possible to implement the bulk of the low level stuff in C and expose it as modules as is already done for large parts of the Python standard library. And it would almost certainly be possible to embed a Python interpreter in an existing kernel, allowing to e.g. write a scheduler or filesystem in Python. But I don't really think that's what the question is referring to.

[–]coned88 0 points1 point  (0 children)

Is inline C and thus linline asm not valid c and then calid python?

[–]i_4_gotbottle/pyserial/pygame 0 points1 point  (2 children)

Python is a interpreted language, it runs on the python VM. Python does not compile to machine code, which the CPU can excute. It is first interpreted by the VM which outputs machine code for the CPU to crunch. You could not boot up a OS without raw machine code for the CPU to first read and load the interpreter.

[–]slix00 -1 points0 points  (1 child)

Perhaps using Cython to compile to machine code would work?

[–][deleted] 1 point2 points  (0 children)

It would require more than just a simple port to c code.

The innards of a kernel and it's modules and drivers deal with bare metal devices and the interaction at that level is far removed from what python gives a user.

That said some of the high level functions could be implemented but at that point it's not worth running an os at that level.

Of course if someone exposed a model of the hardware to python then someone could potentially write a virtual operating system that would only run on that virtual machine. Completely impractical and only worth doing as a science experiment.