I met a strange thing in Python:
>>> import multiprocessing
>>> thread_pool = multiprocessing.dummy.Pool()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dummy'
However, when I try the following:
>>> from multiprocessing.dummy import Pool as ThreadPool
>>> ThreadPool()
<multiprocessing.pool.ThreadPool object at 0x7faf9308d4a8>
and
>>> import multiprocessing.dummy
>>> multiprocessing.dummy.Pool()
<multiprocessing.pool.ThreadPool object at 0x7faf9308d2e8>
Everything is OK.
I know the difference between import xxx
and from xxx import
, I wonder why It raise AttributeError. My question is why I couldn't use multiprocessing.dummy
after import multiprocessing
?