ThreadPoolExecutor is not defined [python3]

I'm trying to run the following code, which was directly copied from the documentation: :

import executor
import concurrent.futures
import time

def wait_on_b():
    time.sleep(5)
    print(b.result()) # b will never complete because it is waiting on a.                                
    return 5

def wait_on_a():
    time.sleep(5)
    print(a.result()) # a will never complete because it is waiting on b.                                
    return 6


executor = ThreadPoolExecutor(max_workers=2)
a = executor.submit(wait_on_b)
b = executor.submit(wait_on_a)

And I get the following output:

Traceback (most recent call last):
  File "test1.py", line 16, in <module>
    executor = ThreadPoolExecutor(max_workers=2)
NameError: name 'ThreadPoolExecutor' is not defined

I'm assuming that I forgot to import something, but I don't know.


ANSWERS:


Either use from concurrent.futures import ThreadPoolExecutor instead of import concurrent.futures, or leave the import as-is and use executor = concurrent.futures.ThreadPoolExecutor(maxworkers=2).

Also note that the example code you copied is designed to deadlock, so it's not going to work properly once you fix the import issue.



 MORE:


 ? ThreadPoolExecutor is not defined [python3]
 ? ThreadPoolExecutor is not defined [python3]
 ? How to inspect generators in the repl/ipython in Python3
 ? Python3: ReferenceError: weakly-referenced object no longer exists
 ? body = 'cmd=' + urllib_parse.quote_plus(unicode(verb).encode('utf-8')) returns "name 'unicode' is not defined"
 ? body = 'cmd=' + urllib_parse.quote_plus(unicode(verb).encode('utf-8')) returns "name 'unicode' is not defined"
 ? body = 'cmd=' + urllib_parse.quote_plus(unicode(verb).encode('utf-8')) returns "name 'unicode' is not defined"
 ? How to convert Selenese (html) to Python programmatically?
 ? python3 manage.py migrate exceptions
 ? Read a page after another from a drop down menu - Can't find the drop down on 2nd page