Changeset 919:2ce8ca39525b for src/mlx/singleton.py
- Timestamp:
- 03/24/19 08:15:59 (5 years ago)
- Branch:
- python3
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/singleton.py
r401 r919 1 1 2 from util import utf2unicode2 from .util import utf2unicode 3 3 4 4 import os … … 59 59 break 60 60 61 print "singleton._PipeServer.run: created the pipe"61 print("singleton._PipeServer.run: created the pipe") 62 62 try: 63 63 if win32pipe.ConnectNamedPipe(handle)==0: 64 print "singleton._PipeServer.run: client connection received"64 print("singleton._PipeServer.run: client connection received") 65 65 (code, message) = \ 66 66 win32file.ReadFile(handle, … … 69 69 70 70 if code==0: 71 print "singleton._PipeServer.run: message received from client"71 print("singleton._PipeServer.run: message received from client") 72 72 self._raiseCallback() 73 73 else: 74 print "singleton._PipeServer.run: failed to read from the pipe"75 except Exception ,e:76 print "singleton._PipeServer.run: exception:",77 print utf2unicode(str(e))74 print("singleton._PipeServer.run: failed to read from the pipe") 75 except Exception as e: 76 print("singleton._PipeServer.run: exception:", end=' ') 77 print(utf2unicode(str(e))) 78 78 finally: 79 79 win32pipe.DisconnectNamedPipe(handle) 80 80 win32file.CloseHandle(handle) 81 except Exception ,e:82 print "singleton._PipeServer.run: fatal exception:",83 print utf2unicode(str(e))81 except Exception as e: 82 print("singleton._PipeServer.run: fatal exception:", end=' ') 83 print(utf2unicode(str(e))) 84 84 85 85 def _createPipe(self): … … 96 96 None) 97 97 if handle==win32file.INVALID_HANDLE_VALUE: 98 print "singleton._PipeServer.run: could not create the handle"98 print("singleton._PipeServer.run: could not create the handle") 99 99 return None 100 100 else: … … 144 144 f.close() 145 145 return 146 except Exception ,e:147 print "SingleInstance._notifySingleton: failed:",148 print utf2unicode(str(e))146 except Exception as e: 147 print("SingleInstance._notifySingleton: failed:", end=' ') 148 print(utf2unicode(str(e))) 149 149 time.sleep(0.5) 150 150 151 def __ nonzero__(self):151 def __bool__(self): 152 152 """Return a boolean representation of the object. 153 153 … … 194 194 s.recv(64) 195 195 self._raiseCallback() 196 except Exception ,e:197 print "singleton._SocketServer.run: fatal exception:",198 print utf2unicode(str(e))196 except Exception as e: 197 print("singleton._SocketServer.run: fatal exception:", end=' ') 198 print(utf2unicode(str(e))) 199 199 200 200 class SingleInstance(object): … … 218 218 fcntl.lockf(self._lockFile, fcntl.LOCK_EX | fcntl.LOCK_NB) 219 219 self._isSingle = True 220 except Exception ,e:220 except Exception as e: 221 221 self._lockFile.close() 222 222 self._lockFile = None … … 259 259 s.close() 260 260 return 261 except Exception ,e:262 print "singleton.SingleInstance._notifySingleton: failed:",263 print utf2unicode(str(e))261 except Exception as e: 262 print("singleton.SingleInstance._notifySingleton: failed:", end=' ') 263 print(utf2unicode(str(e))) 264 264 time.sleep(0.5) 265 265 266 def __ nonzero__(self):266 def __bool__(self): 267 267 """Return a boolean representation of the object. 268 268 … … 299 299 if __name__=="__main__": 300 300 def raiseCallback(): 301 print "Raise the window!"301 print("Raise the window!") 302 302 303 303 instance = SingleInstance("mlx", raiseCallback) 304 304 if instance: 305 print "The first instance"305 print("The first instance") 306 306 time.sleep(10) 307 307 else: 308 print "The program is already running."309 308 print("The program is already running.") 309
Note:
See TracChangeset
for help on using the changeset viewer.