# Python閉包與多線程

I had my position transferred for more than one week from Mobile Security to Clean Master, and have a chance to make a framework to transfer data from one database to another, also some annoying jobs are still in my hand.

Taking the benefits of the Internet and some my old projects, it's easy to frame a framework. Using multi-thread multi-process to do this.

I would like to share that a problem when I try to put an closure inside the thread pool.

code just like this.

def wrap():
a = [0]
def init_th():
using a here...
a[0] += 1
return init_th

def work(init_th):
init_th()
....
return

threading.Thread(target=work, arg=(wrap(), ))

As a result, it comes with the thread safety problem. needs a mutex for the init_th.

In fact, I suddenly know that the GIL never make the thread safety, it just remove some basic problems and make it safe in line-level.

02-03 51
10-02 581
12-03 1178
09-19 395
03-26 13
09-28
09-04
12-18 44万+