Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2009 Doug Hellmann All rights reserved.
  5. #
  6. """
  7. """
  8. #end_pymotw_header
  9.  
  10. import resource
  11. import sys
  12. import signal
  13. import time
  14.  
  15. # Set up a signal handler to notify us
  16. # when we run out of time.
  17. def time_expired(n, stack):
  18. print 'EXPIRED :', time.ctime()
  19. raise SystemExit('(time ran out)')
  20.  
  21. signal.signal(signal.SIGXCPU, time_expired)
  22.  
  23. # Adjust the CPU time limit
  24. soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
  25. print 'Soft limit starts as :', soft
  26.  
  27. resource.setrlimit(resource.RLIMIT_CPU, (1, hard))
  28.  
  29. soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
  30. print 'Soft limit changed to :', soft
  31. print
  32.  
  33. # Consume some CPU time in a pointless exercise
  34. print 'Starting:', time.ctime()
  35. for i in range(200000):
  36. for i in range(200000):
  37. v = i * i
  38.  
  39. # We should never make it this far
  40. print 'Exiting :', time.ctime()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement