import signal

from pyuv_cffi import Loop, Timer, Signal


def sig_cb(sig_h, sig_num):
    print('\nsig_cb({}, {})'.format(sig_h, sig_num))
    sig_h.stop()
    sig_h.loop.stop()


def timer_cb(timer_h):
    print('timer_cb({})'.format(timer_h))


def run():
    loop = Loop()

    timer_h = Timer(loop)
    timer_h.start(timer_cb, 1, 1)

    sig_h = Signal(loop)
    sig_h.start(sig_cb, signal.SIGINT)

    status = loop.run()

    timer_h.close()  # stop and free any timers before freeing the loop
    print('loop.run() -> ', status)


def main():
    run()


if __name__ == '__main__':
    main()

import signal

from pyuv_cffi import Loop, Timer, Signal


def sig_cb(sig_h, sig_num):
    print('\nsig_cb({}, {})'.format(sig_h, sig_num))
    sig_h.stop()
    sig_h.loop.stop()


def timer_cb(timer_h):
    print('timer_cb({})'.format(timer_h))


def run():
    loop = Loop()

    timer_h = Timer(loop)
    timer_h.start(timer_cb, 1, 1)

    sig_h = Signal(loop)
    sig_h.start(sig_cb, signal.SIGINT)

    status = loop.run()

    timer_h.close()  # we must stop and free any other handles before freeing the loop
    print('loop.run() -> ', status)

    # all handles in pyuv_cffi (including the loop) are automatically freed when they go out of
    # scope


def main():
    run()


if __name__ == '__main__':
    main()

Add inline comment regarding freeing resources
Add inline comment regarding freeing resources

  import signal
  
  from pyuv_cffi import Loop, Timer, Signal
  
  
  def sig_cb(sig_h, sig_num):
      print('\nsig_cb({}, {})'.format(sig_h, sig_num))
      sig_h.stop()
      sig_h.loop.stop()
  
  
  def timer_cb(timer_h):
      print('timer_cb({})'.format(timer_h))
  
  
  def run():
      loop = Loop()
  
      timer_h = Timer(loop)
      timer_h.start(timer_cb, 1, 1)
  
      sig_h = Signal(loop)
      sig_h.start(sig_cb, signal.SIGINT)
  
      status = loop.run()
  
-     timer_h.close()  # stop and free any timers before freeing the loop
+     timer_h.close()  # we must stop and free any other handles before freeing the loop
      print('loop.run() -> ', status)
+ 
+     # all handles in pyuv_cffi (including the loop) are automatically freed when they go out of
+     # scope
  
  
  def main():
      run()
  
  
  if __name__ == '__main__':
      main()
  
Add inline comment regarding freeing resources
## Code Before:
import signal

from pyuv_cffi import Loop, Timer, Signal


def sig_cb(sig_h, sig_num):
    print('\nsig_cb({}, {})'.format(sig_h, sig_num))
    sig_h.stop()
    sig_h.loop.stop()


def timer_cb(timer_h):
    print('timer_cb({})'.format(timer_h))


def run():
    loop = Loop()

    timer_h = Timer(loop)
    timer_h.start(timer_cb, 1, 1)

    sig_h = Signal(loop)
    sig_h.start(sig_cb, signal.SIGINT)

    status = loop.run()

    timer_h.close()  # stop and free any timers before freeing the loop
    print('loop.run() -> ', status)


def main():
    run()


if __name__ == '__main__':
    main()

## Instruction:
Add inline comment regarding freeing resources
## Code After:
import signal

from pyuv_cffi import Loop, Timer, Signal


def sig_cb(sig_h, sig_num):
    print('\nsig_cb({}, {})'.format(sig_h, sig_num))
    sig_h.stop()
    sig_h.loop.stop()


def timer_cb(timer_h):
    print('timer_cb({})'.format(timer_h))


def run():
    loop = Loop()

    timer_h = Timer(loop)
    timer_h.start(timer_cb, 1, 1)

    sig_h = Signal(loop)
    sig_h.start(sig_cb, signal.SIGINT)

    status = loop.run()

    timer_h.close()  # we must stop and free any other handles before freeing the loop
    print('loop.run() -> ', status)

    # all handles in pyuv_cffi (including the loop) are automatically freed when they go out of
    # scope


def main():
    run()


if __name__ == '__main__':
    main()
