developing for modularity & reusability: how to handle While True loops? <p>I've been playing around with the pybluez module recently to scan for nearby Bluetooth devices. What I want to do now is extend the program to also find nearby WiFi client devices.</p> <p>The WiFi client scanner will have need to have a <code>While True</code> loop to continually monitor the airwaves. If I were to write this as a straight up, one file program, it would be easy.</p> <pre><code>import ... while True: client = scan() print client['mac'] </code></pre> <p>What I want, however, is to make this a module. I want to be able to reuse it later and, possible, have others use it too. What I can't figure out is how to handle the loop.</p> <pre><code>import mymodule scan() </code></pre> <p>Assuming the first example code was 'mymodule', this program would simply print out the data to stdout. I would want to be able to use this data in my program instead of having the module print it out...</p> <p>How should I code the module?</p>