回答編集履歴

2

補足: 質問文に nfc なしのケースについて言及があったので、説明の細部を補足。

2020/08/30 13:55

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
  もし、影響が無かったとしたら、
50
50
 
51
- nfc なしで問題が発生するかどうかを試してみてください。
51
+ nfc なし(補足: スレッドは使って)で問題が発生するかどうかを試してみてください。
52
52
 
53
53
 
54
54
 

1

関数がどのスレッドで実行されているのか、把握しやすいようにロギングを設定

2020/08/30 13:55

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -60,23 +60,23 @@
60
60
 
61
61
 
62
62
 
63
-
64
-
65
63
  import tkinter as tk
66
64
 
67
65
  from threading import Thread
68
66
 
69
-
67
+ import logging
70
68
 
71
69
 
72
70
 
73
71
  def thread_main(root):
74
72
 
73
+ logging.info("thread_main started")
74
+
75
+ logging.info("Open Dialog")
76
+
75
- win = tk.Toplevel(root)
77
+ win = tk.Toplevel()
76
78
 
77
79
  win.geometry("100x100+100+100")
78
-
79
-
80
80
 
81
81
 
82
82
 
@@ -87,6 +87,8 @@
87
87
 
88
88
 
89
89
  def start():
90
+
91
+ logging.info("Button clicked")
90
92
 
91
93
  thread = Thread(target=thread_main, args=(root,), daemon=True)
92
94
 
@@ -101,6 +103,8 @@
101
103
 
102
104
 
103
105
  if __name__ == '__main__':
106
+
107
+ logging.basicConfig(level=logging.INFO, format="[%(threadName)s] %(message)s")
104
108
 
105
109
  main()
106
110
 
@@ -118,15 +122,17 @@
118
122
 
119
123
 
120
124
 
121
-
122
-
123
125
  import tkinter as tk
124
126
 
125
127
  from threading import Thread
126
128
 
129
+ import logging
130
+
127
131
 
128
132
 
129
133
  def open_dialog(root):
134
+
135
+ logging.info("Open Dialog")
130
136
 
131
137
  win = tk.Toplevel(root)
132
138
 
@@ -136,13 +142,9 @@
136
142
 
137
143
  def thread_main(root):
138
144
 
139
- # これは有用なスレッドの利用例ではありませんが、
140
-
141
- # 動作検証の為、サブスレッドからメインスレッドで open_dialog を呼ぶ
145
+ logging.info("thread_main started")
142
146
 
143
147
  root.after_idle(open_dialog, root)
144
-
145
-
146
148
 
147
149
 
148
150
 
@@ -153,6 +155,8 @@
153
155
 
154
156
 
155
157
  def start():
158
+
159
+ logging.info("Button clicked")
156
160
 
157
161
  thread = Thread(target=thread_main, args=(root,), daemon=True)
158
162
 
@@ -168,6 +172,8 @@
168
172
 
169
173
  if __name__ == '__main__':
170
174
 
175
+ logging.basicConfig(level=logging.INFO, format="[%(threadName)s] %(message)s")
176
+
171
177
  main()
172
178
 
173
179
  ```