# Buggy code
def _get_thread_count():
    return 40


# Traceback (IOError)
[Errno 24] Too many open files
Traceback (most recent call last):
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/main.py", line 36, in main
cmd_result = APPLICATION.execute(args)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/core/application.py", line 210, in execute
result = expanded_arg.func(params)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 289, in __call__
return self.handler(*args, **kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 488, in _execute_command
reraise(*sys.exc_info())
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 465, in _execute_command
result = op(client, **kwargs) if client else op(**kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/command_modules/vm/custom.py", line 211, in list_vm_images
all_images = load_images_thru_services(publisher_name, offer, sku, image_location)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/command_modules/vm/_actions.py", line 67, in load_images_thru_services
t.result()  # don't use the result but expose exceptions from the threads
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/concurrent/futures/_base.py", line 422, in result
return self.__get_result()
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/concurrent/futures/thread.py", line 62, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/cli/command_modules/vm/_actions.py", line 50, in _load_images_from_publisher
images = client.virtual_machine_images.list(location, publisher, o.name, s.name)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/azure/mgmt/compute/compute/v2016_04_30_preview/operations/virtual_machine_images_operations.py", line 172, in list
response = self._client.send(request, header_parameters, **operation_config)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/msrest/service_client.py", line 180, in send
**kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/requests/sessions.py", line 513, in request
resp = self.send(prep, **send_kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/requests/sessions.py", line 623, in send
r = adapter.send(request, **kwargs)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/connectionpool.py", line 844, in _validate_conn
conn.connect()
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/connection.py", line 326, in connect
ssl_context=context)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/util/ssl_.py", line 325, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 440, in wrap_socket
rd = util.wait_for_read(sock, sock.gettimeout())
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/util/wait.py", line 33, in wait_for_read
return _wait_for_io_events(socks, EVENT_READ, timeout)
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/util/wait.py", line 22, in _wait_for_io_events
with DefaultSelector() as selector:
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/util/selectors.py", line 581, in DefaultSelector
return _DEFAULT_SELECTOR()
File "/Users/debekoe/lib/azure-cli/lib/python2.7/site-packages/urllib3/util/selectors.py", line 461, in __init__
self._kqueue = select.kqueue()
IOError: [Errno 24] Too many open files

# Fixed code
def _get_thread_count():
    return 5  # don't increase too much till https://github.com/Azure/msrestazure-for-python/issues/6 is fixed