Howard Klein

Howard Klein

Musings on software, discrete event simulation and other pseudo-random topics

Posts filed under Python

Random() Adventures

Better to remain silent and be thought a fool than to speak and to remove all doubt. Often, but probably incorrectly, attributed to Mark Twain   The idea of writing about random number generation (I mean, pseudo-random number generation, but that term involves way too much typing) makes me extremely nervous.  When it comes to… (read more)

Evaluating Python Coroutine Options

A couple of previous posts (here and here) presented three Python-based alternatives for expressing process or agent-based behavior that takes place over (or blocks for) simulated time: generators, greenlets and tasklets. So which approach is best?  There are (at least!) three factors to consider: Ease of use – ease-of-coding, expressiveness, maintainability. Eco-system factors – compatibility… (read more)

Simulating an M/M/1 Queue Using Generators and Greenlets

My last two posts (here and here) introduced three Python-based alternatives for expressing simulation process or agent-based behavior that takes place over (or blocks for) simulated time: Generators, a core feature of the Python language Greenlets, provided by the third-party greenlet Python extension package Tasklets, provided by two standalone Python distributions, Stackless Python and PyPy… (read more)

Python Coroutine Options, Part 2: Greenlets and Tasklets

In my last post, I discussed Python’s built-in support for coroutines via generators.  While we can use generators to implement simulation process code, the essentially stackless nature of generator functions limit their expressiveness and power. Once we venture beyond Python’s standard library, there are a couple of other options that facilitate completely stackful coroutines: greenlets… (read more)

Python Coroutine Options, Part 1: Generators

As I mentioned here, coroutines provide a means to express processes occurring over simulated time in a pretty natural way. Python has one built-in mechanism, the generator, which enables coroutine-like functionality.  Two other flavors of coroutine, greenlets and tasklets, are implemented by third-party packages; these will be discussed in a later post.