Sleep sort in Python

People keep coming up with smart ideas, even though sometimes they might not be useful for scaling up. One such example is that of sleep sort, which works like a charm, albeit I highly doubt that it would work for a long array. It certainly won’t work for negative numbers. Whether it works for real numbers or not depends on the implementation. Here’s a simple Python script I wrote, taking from the original idea, that works for integers. The idea is simple – for each number in an array, read the number, spawn a new process, count to the number, and then print the number.

I am using multiprocessing, which is allegedly better than threading, because it side-steps the Global Interpreter Lock in Python by using subprocesses rather than threads.

Oftentimes in computing you just have to look at an idea and smile at its beauty, even if you won’t really ever use it in your work.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s