hgext/inotify/server.py
branchstable
changeset 10494 08064db9f005
parent 10282 08a0f04b56bd
child 11545 db9d16233787
equal deleted inserted replaced
10493:283f3b413f19 10494:08064db9f005
    16 import struct
    16 import struct
    17 import sys
    17 import sys
    18 import tempfile
    18 import tempfile
    19 
    19 
    20 class AlreadyStartedException(Exception):
    20 class AlreadyStartedException(Exception):
       
    21     pass
       
    22 class TimeoutException(Exception):
    21     pass
    23     pass
    22 
    24 
    23 def join(a, b):
    25 def join(a, b):
    24     if a:
    26     if a:
    25         if a[-1] == '/':
    27         if a[-1] == '/':
   442     raise ImportError
   444     raise ImportError
   443 
   445 
   444 master = _server.master
   446 master = _server.master
   445 
   447 
   446 def start(ui, dirstate, root, opts):
   448 def start(ui, dirstate, root, opts):
   447     timeout = opts.get('timeout')
   449     timeout = opts.get('idle_timeout')
   448     if timeout:
   450     if timeout:
   449         timeout = float(timeout) * 1e3
   451         timeout = float(timeout) * 60000
       
   452     else:
       
   453         timeout = None
   450 
   454 
   451     class service(object):
   455     class service(object):
   452         def init(self):
   456         def init(self):
   453             try:
   457             try:
   454                 self.master = master(ui, dirstate, root, timeout)
   458                 self.master = master(ui, dirstate, root, timeout)
   455             except AlreadyStartedException, inst:
   459             except AlreadyStartedException, inst:
   456                 raise util.Abort("inotify-server: %s" % inst)
   460                 raise util.Abort("inotify-server: %s" % inst)
   457 
   461 
   458         def run(self):
   462         def run(self):
   459             try:
   463             try:
   460                 self.master.run()
   464                 try:
       
   465                     self.master.run()
       
   466                 except TimeoutException:
       
   467                     pass
   461             finally:
   468             finally:
   462                 self.master.shutdown()
   469                 self.master.shutdown()
   463 
   470 
   464     if 'inserve' not in sys.argv:
   471     if 'inserve' not in sys.argv:
   465         runargs = util.hgcmd() + ['inserve', '-R', root]
   472         runargs = util.hgcmd() + ['inserve', '-R', root]