質問編集履歴

1

書式の改善

2016/09/14 07:42

投稿

miyahan
miyahan

スコア3095

test CHANGED
@@ -1 +1 @@
1
- multiprocessing使うとloggingの出力がダブる
1
+ Pythonでmultiprocessing使用時にloggingの出力がダブる
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  class Hoge:
30
30
 
31
- def __init__(self, num):
31
+ def __init__(self):
32
32
 
33
33
  self.logger = logging.getLogger('HogeClass')
34
34
 
@@ -36,13 +36,11 @@
36
36
 
37
37
  self.logger.setLevel(logging.DEBUG)
38
38
 
39
- self.num = num
40
39
 
41
40
 
41
+ def child(self, num):
42
42
 
43
- def child(self):
44
-
45
- self.logger.info('I am {}, pid {}'.format(self.num, os.getpid()))
43
+ self.logger.info('I am {}, pid {}'.format(num, os.getpid()))
46
44
 
47
45
  time.sleep(1)
48
46
 
@@ -54,9 +52,9 @@
54
52
 
55
53
  def mp_hoge(num):
56
54
 
57
- h = Hoge(num)
55
+ h = Hoge()
58
56
 
59
- h.child()
57
+ h.child(num)
60
58
 
61
59
 
62
60