title: Python: Implementing concurrent DNS requests (pipelining)
body: <p>I'm trying to write a python script that sends multiple DNS requests, using a different name server for each request.</p>
  
  <p>Implementing a sequential solution is easy using dnspython but too slow for me. 
  Adding concurrency using thread pool is not possible as, in my particular case, all requests use the same source port (REUSE_ADDRESS won't help here either).</p>
  
  <p>For the above reasons I'm thinking about using the following solution (ditching the use of dnspython's resolver module but taking advantage of its message building and parsing modules):</p>
  
  <ul>
  <li>Allowing up to X requests to be in progress </li>
  <li>Send X requests simultaneously (just sending dns request packets using udp. Probably with added delay between sends to avoid bursts)</li>
  <li>A different thread wait for responses</li>
  <li>When a response arrives match it with the request (by address) and allow a new request to run</li>
  <li>If a response to request does not arrive within TIMEOUT seconds mark it as completed and allow a new request to run</li>
  </ul>
  
  <p>My main issues here are:</p>
  
  <ul>
  <li>How to implement the task timeout easily</li>
  <li>Is it possible to implement it without the use of thread synchronization (e.g. using event loop?) </li>
  <li>Is there any existing library that can help implementing it (it really feels like I'm trying to reinvent the wheel here, I looked into the asycnio module but couldn't figure out a way to take advantage of it for my problem). Note that I don't want to use existing dns or network libraries as I need the flexibility of changing core functionality (e.g. using raw sockets, changing DNS header fields, etc.).</li>
  </ul>