SHARE
TWEET

test_script.py

a guest Mar 13th, 2012 31 Never
  1. import kaboom
  2. import stackless
  3.  
  4. from kaboom import *
  5.  
  6. # This implements the C++ interface that was wrapped for Python.
  7. # The wrapper is called first, which gets the override for ReceiveExplosion.
  8. # In there is code to ensure we have the GIL, and to release it afterwards.
  9. # We're setting a stop variable kind of like I originally was doing in the more
  10. # complicated code.  I have found it doesn't actually matter, but should work
  11. # when all is done.
  12. class PoorGuy(ITimeBombCallback):
  13.     def __init__(self, stop_var):
  14.         ITimeBombCallback.__init__(self)    # Very important for subclasses in Boost.Python
  15.         self.stop_var = stop_var
  16.  
  17.     def ReceiveExplosion(self):
  18.         print "Got explosion"
  19.         self.stop_var = True
  20.  
  21. stop_var = False
  22. poorGuy = PoorGuy(stop_var)
  23. bomb = TimeBomb(poorGuy)
  24. bomb.Go()
  25.  
  26. # Busy loop
  27. while not stop_var:
  28.     stackless.schedule()
  29.    
  30. bomb.Join()
RAW Paste Data
Top