<div id="yiv2064358590">I recently also dealt with threads, and ran into similar issues. For example, I was surprised to learn that there is no command to kill threads, instead I had to add code in server threads to get them out of the server loop.<br><br>I have concluded a while ago that "sleeping" in tests (your function wait_for_some_time) should really be avoided, for the reasons you state: wait not long enough, and your tests become unstable. Wait too long, and you are wasting time.<br><br>So why do you sleep? Abstractly speaking, you are waiting for some time and hope that after this time some condition is fulfilled. In our case, you want to wait long enough for the consumer to have consumed all data. In order to avoid the sleep, you need to have your code signal this condition directly, I my code I used the Event objects of the threading module. So the suggestion is that the consumer signal an empty queue via an event, and that the testing code waits for this
 event<br><br>The advantages of  this approach are obvious: no need to choose a wait time, your tests run with full speed.<br><br>The disadvantage of this approach might be that the signaling of the event is maybe only needed for testing, and is not necessary for production code. I don't know the testing literature, so I don't know if it says something about such testing artifacts. I personally value fast and reliable tests very highly, so I would just leave this artifact in the code.<br><br>Maybe I should mention that my own testing code is not working yet, since I turned my attention away from the threading aspects of the application to deal with other areas first.<br><br>One of the things I want to test is some sort of timeout mechanism: the application hands off some task to some separate process, and needs some fall back mechanism in case this process dies or is inaccessible (it might run on another machine). I will use the time.sleep function in the production code,
 but for testing, I will run my application on "simulated time" rather than real time, so that, again, the tests can run at full speed. One question I have is: how do I model this? I could replace the function sleep in the time module for testing, but I am afraid that changing standard functions might interfere with the testing framework.<br><br>My current (planned, since the tests are not quite functional yet) solution is to introduce an indirection: import time.sleep into some module called SystemInterfaces, and then import sleep from SystemInterfaces.sleep. This way, my testing scaffolding can substitute a custom sleep function for the standard one.<br><br>Similar issues arise with the interface to the file system.<br><br>Is there some other recommended way to deal with this issue?<br><br><br></div>               <!-- toctype = X-unknown --><!-- toctype = text --><!-- text --><!-- toctype = message --><!-- toctype = X-unknown --><!-- toctype = text --><!-- text
 --><script> var callCount = 0; function rmvScroll( msg ) {  if ( ++callCount > 10 ) { msg.style.visibility = "visible"; }    if ( callCount < 50 && ! imgsDone( msg ) ) {   setTimeout( function() { rmvScroll( msg ); }, 200 );   return;  }  var delta = msg.offsetHeight - msg.clientHeight;  var newWidth = 0;  var newHeight = 0;  delta = ( isNaN( delta )? 1 : delta + 1 );  if ( msg.scrollHeight > msg.clientHeight ) {   newHeight = msg.scrollHeight + delta;  }  delta = msg.offsetWidth - msg.clientWidth;  delta = ( isNaN( delta )? 1 : delta + 1 );  if ( msg.scrollWidth > msg.clientWidth ) {   newWidth = msg.scrollWidth + delta;  }  msg.style.overflow = "visible";  msg.style.visibility = "visible";    if ( newWidth > 0 || newHeight > 0 ) {   var ssxyzzy = document.getElementById( "ssxyzzy" );   var cssAttribs = ['#message {'];   if ( newWidth > 0 ) cssAttribs.push( 'width:' + newWidth + 'px;' );   if ( newHeight > 0 ) cssAttribs.push( ' height:' + newHeight + 'px;' );  
 cssAttribs.push( '}' );   try {    ssxyzzy.sheet.deleteRule( 0 );    ssxyzzy.sheet.insertRule( cssAttribs.join(""), 0 );   } catch( e ){}  } } function imgsDone( msg ) // for Firefox, we need to scan for images that haven't set their width yet {  var imgList = msg.getElementsByTagName( "IMG" );  var len = ((imgList == null)? 0 : imgList.length);  for ( var i = 0; i < len; ++i ) {   var theImg = imgList[i];   if ( ! theImg.complete && "undefined" != typeof theImg.naturalWidth && theImg.naturalWidth == 0 ) {    return false;   }  }  return true; } var msg = document.getElementById( "message" ); if ( oBw.agt.match( /gecko/ ) == "gecko" ) { if ( msg && "undefined" != typeof msg ) { rmvScroll( msg ); } } else { msg.style.visibility = "visible"; } </script><!-- END TOC --> <input name=".crumb" value="c9YdWgiHBxz" type="hidden"><input name="MsgId" value="2430_9138675_4738883_2083_2456_0_233165_7399_4030162760" type="hidden"><input name="box" value="Inbox" type="hidden"><input
 name="MOV" value="" type="hidden"><input name="NewFol" value="" type="hidden"><input name="destBox" value="" type="hidden"><input name="newfoldermessage" value="Please enter a name for your folder." type="hidden"><input name="DEL" value="" type="hidden">                                                                                                                                           <span class="first"></span>