Commits

windwiny  committed 5a54085

win32 subprocess problem:
win32 and python < 2.7, cannot terminate rsync subprocess ;
on py >= 2.7 , add subprocess creationflags
change message

  • Participants
  • Parent commits 3e74357

Comments (0)

Files changed (2)

File mygrsyncdlg.py

 import shlex
 import locale
 import time
+import traceback
 import wx
 import wx.stc
 
     def __init__(self, parent):
         self._init_ctrls(parent)
         self.init2()
-    
+
     def init2(self):
         ff = wx.Font(9, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Courier New')
         self.txtSRC.SetFont(ff)
         self.stcSyncLog.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
         self.stcSyncLog.SetMarginWidth(1, 38)
         self.stcSyncLog.SetLexer(wx.stc.STC_LEX_SQL)
-        self.stcSyncLog.SetKeyWords(0, 'error failed unexpectedly warning vanished deleting inserting sending incremental')
+        self.stcSyncLog.SetKeyWords(0, 'sigint sigterm sighup error failed '
+                                    'unexpectedly warning vanished deleting '
+                                    'inserting sending incremental')
         self.stcSyncLog.StyleSetSpec(wx.stc.STC_SQL_WORD, "fore:#FFFFFF,bold")
         self.stcSyncLog.StyleSetSpec(wx.stc.STC_SQL_WORD, "back:#FF0000")
         self.stcSyncLog.SetKeyWords(1, 'total size dry run')
                 sp.terminate()
                 if sp.poll() is None: # XXXX win32 sp may has problem
                     print '  Terminate %s, Failed !!!' % str(sp)
-                    try: sp.kill()
+                    try:    # win32 py>=2.7 0:signal.CTRL_C_EVENT 1:signal.CTRL_BREAK_EVENT
+                        sp.send_signal(1)
+                    except:
+                        print '---------\n%s\n---------\n' % traceback.format_exc()
+                    try:    # not win32
+                        sp.kill()
                     except:
                         if sp in self.sp: self.sp.remove(sp)
                 else:
     def create_subproc_logthread(self, cmd):
         sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
-                              startupinfo=G.startupinfo)
+                              startupinfo=G.startupinfo,
+                              creationflags=G.creationflags)
         self.sp.append(sp)
 
         def thpg(sp, self):

File mygrsyncframe.py

     _pg_GUIDIFF = 'bc2'
 
     if sys.platform == 'win32':
-        startupinfo = subprocess.STARTUPINFO()
-        if sys.version.startswith('2.7') or sys.version.startswith('2.6'):
+        if sys.version >= '2.6':
             nn = subprocess._subprocess
         else :
             nn = subprocess
+        startupinfo = subprocess.STARTUPINFO()
         startupinfo.dwFlags |= nn.STARTF_USESHOWWINDOW
         startupinfo.wShowWindow = nn.SW_HIDE
+        if sys.version >= '2.7':
+            # win32 py>=2.7 subprocess._subprocess.CREATE_NEW_PROCESS_GROUP
+            creationflags = 512
+        else:
+            creationflags = 0
     else:
         startupinfo = None
+        creationflags = 0
 
     db = sqlite3.connect(':memory:')
     cs = db.cursor()
     def getall(cls):
         cls.cs.execute('''select distinct l, r from KV order by upper(l)''')
         return cls.cs.fetchall()
-    
+
     @classmethod
     def showall(cls):
         i = 0
             print '%s "%s" "%s"' % (G._pg_GUIDIFF, l, r)
         else:
             subprocess.Popen('%s "%s" "%s"' % (G._pg_GUIDIFF, l, r))
-    
-    @staticmethod 
+
+    @staticmethod
     def runsync(l, r, parent=None):
         lu = G.cygpath(l)
         ru = G.cygpath(r)
         dlg.txtExclude.SetValue('  '.join(excludes))
         dlg.Show()
 
-    
+
 def create(parent):
     return mygrsync(parent)