title: How to change the stack size of subprocess in Python
body: <p>Here's my somewhat complicated setup that has just begun to cause a StackOverflow exception a couple of days ago:</p>
  
  <p>On my windows-based continuous integration platform I have got a Jenkins job that starts a Python script.
  This Python script runs a cmake command, an msbuild call and then executes the newly compiled gtest-based test framwork.
  The msbuild produces a dll and the gtest executable. The executable itself then loads the dll in order to test it.</p>
  
  <p>A couple of days ago I made some changes in the source code of the dll that alter the memory footprint of some of my structures (basically just array lengths). It's plain C code. Now some of the tests exit with a stack-overflow exception.</p>
  
  <p>I admit I'm putting some data structures on the stack that don't necessarily have to be there but it's the best I've got for information hiding in C (better than using static global variables). </p>
  
  <pre><code>if(myCondition)
  {
      int hugeBuffer[20000];
      ...
  }
  </code></pre>
  
  <p>Apart from that there is no recursion or anything fancy going on that could be a legit source of trouble. Large chunks of data are always passed by reference (pointer).</p>
  
  <p>Anyway, the stack overflow exception doesn't occur on my local machine running the gtest executable directly from Visual Studio unless I significantly reduce the reserved stack memory in the linker settings.
  Then in debug mode I clearly run into a point where the stack just overflows at the beginning of a function.
  Unfortunately I couldn't find any way of debugging how full the stack is. In VS I've only got the call stack window which doesn't show the current "fill level" of the stack.</p>
  
  <p>So although you guys might kill mir for this I'm guessing I really just don't have enough stack memory available when running the Jenkins job.
  So I'm wondering what step actually defines the amount of stack memory available for my DLL code. It's clearly less than the default 10MB I have in VisualStudio on my local machine.</p>
  
  <p>In the msbuild step there is no STACK parameter used for the linker so I'm guessing the exe header should contain the same value as in Visual Studio (10MB?).
  The Python script runs a subprocess.call which could ignore the value set by the linker and overwrite it. I could neither find any information on that nor on how to change the stack memory allocated. I don't even know whether it spawns a thread or a process which may <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686774%28v=vs.85%29.aspx" rel="nofollow">also affect the stack size</a>.
  The DLL loading mechanism in windows is also somewhat mysterious to me but I'm guessing the dll uses the same stack as the executable using it. I'm using the LoadLibrary() macro from WinBase.h.</p>