Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. def run(self):
  2. """
  3. Start the event loop. Exit the loop when any callback raises
  4. an exception. If ExitMainLoop is raised, exit cleanly.
  5.  
  6. >>> import os
  7. >>> rd, wr = os.pipe()
  8. >>> os.write(wr, "data") # something to read from rd
  9. 4
  10. >>> evl = TwistedEventLoop()
  11. >>> def say_hello_data():
  12. ... print "hello data"
  13. ... os.read(rd, 4)
  14. >>> def say_hello():
  15. ... print "hello"
  16. >>> handle = evl.watch_file(rd, say_hello_data)
  17. >>> def say_being_twisted():
  18. ... print "oh I'm messed up"
  19. ... raise ExitMainLoop
  20. >>> handle = evl.alarm(0.0625, say_being_twisted)
  21. >>> handle = evl.alarm(0.03125, say_hello)
  22. >>> evl.run()
  23. hello data
  24. hello
  25. oh I'm messed up
  26. """
  27. if not self.manage_reactor:
  28. self.reactor.run()
  29. if self._exc_info:
  30. # An exception caused us to exit, raise it now
  31. exc_info = self._exc_info
  32. self._exc_info = None
  33. raise exc_info[0], exc_info[1], exc_info[2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement