title: How to combine python asyncio with threads?
body: <p>I have successfully built a <a href="https://github.com/fxstein/SentientHome/blob/develop/engine/event.engine.py" rel="noreferrer">RESTful microservice</a> with Python asyncio and aiohttp that listens to a POST event to collect realtime events from various feeders.</p>
  
  <p>It then builds an in-memory structure to cache the last 24h of events in a nested defaultdict/deque structure.</p>
  
  <p>Now I would like to periodically checkpoint that structure to disc, preferably using pickle.</p>
  
  <p>Since the memory structure can be >100MB I would like to avoid holding up my incoming event processing for the time it takes to checkpoint the structure.</p>
  
  <p>I'd rather create a snapshot copy (e.g. deepcopy) of the structure and then take my time to write it to disk and repeat on a preset time interval.</p>
  
  <p>I have been searching for examples on how to combine threads (and is a thread even the best solution for this?) and asyncio for that purpose but could not find something that would help me.</p>
  
  <p>Any pointers to get started are much appreciated!</p>