a simple example:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import multiprocessing
class Klass(object):
def __init__(self):
print "Constructor ... %s" % multiprocessing.current_process().name
def __del__(self):
print "... Destructor %s" % multiprocessing.current_process().name
if __name__ == '__main__':
kls = Klass()
run with error when do current_process
in __del__
:
Constructor ... MainProcess
Exception AttributeError: "'NoneType' object has no attribute 'current_process'" in <bound method Klass.__del__ of <__main__.Klass object at 0x7f5c34e52090>> ignored
if I change a variable name:
als = Klass()
it get the right result:
Constructor ... MainProcess
... Destructor MainProcess
and I tried many variable name, some ok, some error.
Why different instance name, will cause multiprocessing module be None in __del__
?
multiprocessing
.