Compare using Thread.Sleep and Timer for delayed execution

One difference is that System.Threading.Timer dispatches the callback on a thread pool thread, rather than creating a new thread every time. If you need this to happen more than once during the life of your application, this will save the overhead of creating and destroying a bunch of threads (a process which is very resource … Read more

Confused, are languages like python, ruby single threaded? unlike say java? (for web apps)

Both Python and Ruby have full support for multi-threading. There are some implementations (e.g. CPython, MRI, YARV) which cannot actually run threads in parallel, but that’s a limitation of those specific implementations, not the language. This is similar to Java, where there are also some implementations which cannot run threads in parallel, but that doesn’t … Read more

Processes, threads, green threads, protothreads, fibers, coroutines: what’s the difference?

OK, I’m going to do my best. There are caveats everywhere, but I’m going to do my best to give my understanding of these terms and references to something that approximates the definition I’ve given. Process: OS-managed (possibly) truly concurrent, at least in the presence of suitable hardware support. Exist within their own address space. … Read more

Threading vs Parallelism, how do they differ?

Daniel Moth (a former coworker of mine)- Threading/Concurrency vs Parallelism article explains it all. Quoted: To take advantage of multiple cores from our software, ultimately threads have to be used. Because of this fact, some developers fall in the trap of equating multithreading to parallelism. That is not accurate…You can have multithreading on a single … Read more

Multithreaded web server in python

Check this post from Doug Hellmann’s blog. from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from SocketServer import ThreadingMixIn import threading class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() message = threading.currentThread().getName() self.wfile.write(message) self.wfile.write(‘\n’) return class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): “””Handle requests in a separate thread.””” if __name__ == ‘__main__’: server = ThreadedHTTPServer((‘localhost’, 8080), Handler) print ‘Starting server, use <Ctrl-C> to stop’ … Read more