Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

rpcserver: cleanup shutdown behavior

The PipeServer class was allocating an event for use in shutting it down
cleanly, so I now use it. While I'm at it I push a request to shut down the
Updater thread. With both of these changes, sys.exit() is no longer necessary.
The app exits cleanly.

Changeset 14737c190a7a

Parent 8617e465db1d

by Steve Borho

Changes to 2 files · Browse files at 14737c190a7a Showing diff from parent 8617e465db1d Diff from another changeset...

Change 1 of 1 Show Entire File taskbar.py Stacked
 
98
99
100
101
102
103
104
105
 
106
107
 
 
 
 
 
 
 
108
109
110
 
98
99
100
 
101
102
 
 
103
104
105
106
107
108
109
110
111
112
113
114
115
@@ -98,13 +98,18 @@
  print "Unknown command -", id     def exit_application(self): - print "stopping pipe server..."   if self.stop_pipe_server():   DestroyWindow(self.hwnd) - print "\n\nGoodbye" - sys.exit() + print "Goodbye"     def stop_pipe_server(self): + print "Stopping pipe server..." + if not self.pipethread.isAlive(): + return True + + # Try the nice way first + self.svc.SvcStop() +   max_try = 10   cnt = 1   while cnt <= max_try and self.pipethread.isAlive():
 
51
52
53
 
54
55
56
 
58
59
60
 
 
 
61
62
63
 
91
92
93
 
 
 
 
 
94
95
96
 
111
112
113
114
 
115
116
117
 
128
129
130
131
 
132
133
134
 
151
152
153
 
 
154
155
156
 
51
52
53
54
55
56
57
 
59
60
61
62
63
64
65
66
67
 
95
96
97
98
99
100
101
102
103
104
105
 
120
121
122
 
123
124
125
126
 
137
138
139
 
140
141
142
143
 
160
161
162
163
164
165
166
167
@@ -51,6 +51,7 @@
  print "shell notified"    requests = Queue.Queue(0) +_abort_request = r';:;:; Quit ;:;:;' # any invalid path would do    class Updater(threading.Thread):   def run(self): @@ -58,6 +59,9 @@
  while True:   batch = []   r = requests.get() + if r == _abort_request: + print 'Updater thread quiting' + return   print "got request %s (first in batch)" % r   batch.append(r)   print "wait a bit for additional requests..." @@ -91,6 +95,11 @@
  # And create an event to be used in the OVERLAPPED object.   self.overlapped.hEvent = win32event.CreateEvent(None,0,0,None)   + def SvcStop(self): + print 'PipeServer thread quiting' + win32event.SetEvent(self.hWaitStop) + requests.put(_abort_request) +   def SvcDoRun(self):   # We create our named pipe.   pipeName = PIPENAME @@ -111,7 +120,7 @@
  sa)     # Loop accepting and processing connections - while 1: + while True:   try:   hr = win32pipe.ConnectNamedPipe(pipeHandle, self.overlapped)   except pywintypes.error, inst: @@ -128,7 +137,7 @@
  rc = win32event.WaitForMultipleObjects(waitHandles, 0, timeout)   if rc==win32event.WAIT_OBJECT_0:   # Stop event - break + return   else:   # read pipe and process request   try: @@ -151,6 +160,8 @@
  print "WARNING: something went wrong in requests.put"   print traceback.format_exc()   status = "ERROR" + # Clean up when we exit + self.SvcStop()    if __name__ == '__main__':   import sys