最近在調試程序時總會莫名奇妙的發生一些異常,就現象來講就是多進程程序莫名奇妙的退出,而且不報出錯的堆棧信息。。。python
改成單進程跟蹤後,發現下面語句中寫錯了個\d:app
def launch(s, e, i) # ... print 'Process -%d\tnum: %d\tsuccess: %d\tdiscard: %d\tnull_num: \d\terr: %d\ttime_clock: %s' % \ (pid, num, cnt, discard, null_num, err, str(time.clock())) # ... if __name__ == "__main__": for i in range(2): _start = 1 _end = 100 pool.apply_async(launch, (_start, _end, i)) pool.close() pool.join()
單進程調試時:ssh
def launch() # ... print 'Process -%d\tnum: %d\tsuccess: %d\tdiscard: %d\tnull_num: \d\terr: %d\ttime_clock: %s' % \ (1, 2, 3, 4, 5, 6, str(time.clock())) # ... if __name__ == "__main__": for i in range(2): _start = 1 _end = 100 pool.apply_async(launch) pool.close() pool.join()
報錯以下:async
Traceback (most recent call last): File "E:/repository/datafuse/snowball/src/abs_person_import_133_debug.py", line 920, in <module> launch(1,100,0) File "E:/repository/datafuse/snowball/src/abs_person_import_133_debug.py", line 907, in launch (pid, num, cnt, discard, null_num, err, str(time.clock())) TypeError: not all arguments converted during string formatting
經分析發現,因爲採用多進程執行方式,在啓動子進程後,進程異常輸出不會在當前終端(ssh 鏈接)顯示,猜想多是子進程不佔用終端輸出,於是不會打印異常堆棧。debug
然而,當程序修改以下後,依然不報錯了。。。。。。(╯‵□′)╯︵┻━┻調試
def launch(a, b, c) # ... print 'Process -%d\tnum: %d\tsuccess: %d\tdiscard: %d\tnull_num: \d\terr: %d\ttime_clock: %s' % \ (a, b, c, 4, 5, 6, str(time.clock())) # ... if __name__ == "__main__": for i in range(2): _start = 1 _end = 100 pool.apply_async(launch, (1, 100, 0)) pool.close() pool.join()
考慮多是因爲使用了參數,致使pool中處理流程發生了改變。code
斷網了。。。(未完待續)orm