tag:help.appveyor.com,2012-11-13:/discussions/problems/2590-it-hangs-when-theres-spawned-process-running-in-backgroundAppVeyor: Discussion 2018-10-19T08:17:21Ztag:help.appveyor.com,2012-11-13:Comment/374759322015-07-24T21:27:11Z2015-07-24T21:27:11ZIt hangs when there's spawned process running in background<div><p>It depends how do you spawn the process (looks like it's Python
- I'm not an expert in it), but there were no issues while starting
background processes from .NET or PowerShell.</p>
<p>You may want to check via RDP: <a href="http://www.appveyor.com/docs/how-to/rdp-to-build-worker">http://www.appveyor.com/docs/how-to/rdp-to-build-worker</a></p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T19:00:45Z2015-07-27T19:00:45ZIt hangs when there's spawned process running in background<div><p>Thanks, @Feodor. I tried RDP. After the test finished, there are
still two python processes running, which is expected as the main
process spawned those. If I kill those two processes, the Appveyor
session will exit and report success. Otherwise, it will just keep
waiting. Is there any configs that I can set so Appveyor doesn't
wait children processes to exit?</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T19:29:01Z2015-07-27T19:29:17ZIt hangs when there's spawned process running in background<div><p>I'm pretty sure it's up to your code whether to wait for child
process for exit or not. Like for example <a href="https://technet.microsoft.com/en-us/library/hh849848.aspx">Start-Process
cmdlet</a> has <code>-Wait</code> flag or
<code>WaitForExit()</code> method in <a href="https://msdn.microsoft.com/en-us/library/fb4aw7b8(v=vs.110).aspx">Process
class</a>.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:01:04Z2015-07-27T20:01:04ZIt hangs when there's spawned process running in background<div><p>Thanks, @Feodor. I can't reproduce the issue locally as running
'python main.py build --job-name UnitOnWindows' exits as expected.
Actually, if I RDP to the VM on AppVeyor, the process has exited as
well. But the two child processes are still alive. Then it seems
really weird that why the next test script never gets executed? The
parent process of the previous test script has already exited.</p>
<p>Screenshot:<br>
.clusterrunner_master.pid stores the master service pid
.clusterrunner_slave.pid stores the slave service pid There were
only two python processes running in background. But the next test
script never gets started.</p>
<p>Thanks for your help, Feodor!</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:06:05Z2015-07-27T20:06:05ZIt hangs when there's spawned process running in background<div><p>BTW, I ran exact the same command on the VM manually, and it
exited as expected. Is it possible that AppVeyor can prevent moving
to the next test command if the child processes of the previous one
are still running?</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:31:20Z2015-07-27T20:31:20ZIt hangs when there's spawned process running in background<div><p>If you mean lines under <code>test</code> section then yes - all
commands are being run synchronously.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:38:45Z2015-07-27T20:38:45ZIt hangs when there's spawned process running in background<div><p>It's under <code>test_script</code> section. And it's about
child process. E.g.</p>
<p>test_script:<br>
- command_1 (spawns process_1 and process_2) - command_2</p>
<p>After command_1 exits, as process_1 and process_2 are still
running. Seems like Appveyor won't move to command_2, in this case.
Is this expected? Can I avoid this behavior if possible?</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:41:17Z2015-07-27T20:41:28ZIt hangs when there's spawned process running in background<div><p>No, when command_1 exists it should move to command_2.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:44:43Z2015-07-27T20:44:43ZIt hangs when there's spawned process running in background<div><p>Thanks, Feodor! But according to the screenshots, I don't think
that's what happened. Would you please help me look into it a
little bit?</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T20:55:11Z2015-07-27T20:55:11ZIt hangs when there's spawned process running in background<div><p>OK, try something like:</p>
<pre>
<code>test:
- command_1
- echo After command 1
- command_2</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:01:48Z2015-07-27T21:01:48ZIt hangs when there's spawned process running in background<div><p>I assume you're talking about <code>test_script</code>?
(<a href="http://www.appveyor.com/docs/appveyor-yml">http://www.appveyor.com/docs/appveyor-yml</a>)</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:02:15Z2015-07-27T21:02:15ZIt hangs when there's spawned process running in background<div><p>Right, sure.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:09:59Z2015-07-27T21:09:59ZIt hangs when there's spawned process running in background<div><p>Fresh build with adding 'echo in the test_script': <a href="https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.64">
https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.64</a></p>
<p>As you can see that it never got to the echo part. I've put log
statement, and even RDP to the VM to make sure command_1 actually
has already exited. If I kill child_process_1 and child_process_2,
Appveyor will pick up the next command as expected.</p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:19:45Z2015-07-27T21:19:45ZIt hangs when there's spawned process running in background<div><p>By command_1 you mean <code>python main.py build --job-name
UnitOnWindows</code> line and you're sure that it exists "python"
process and should move the next "echo" line, correct?</p>
<p>OK, you can do another test by creating a wrapper
<code>test.cmd</code> with something like:</p>
<pre>
<code>python main.py build --job-name UnitOnWindows
echo This message should be displayed</code>
</pre>
<p>and then call it as:</p>
<pre>
<code>test_script:
- test.cmd
- python main.py stop</code>
</pre>
<p>so <code>test.cmd</code> is run as a whole and doesn't depend on
AppVeyor flow.</p>
<p>If the process exists you should see <code>This message should
be displayed</code> in a build log.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:35:45Z2015-07-27T21:35:45ZIt hangs when there's spawned process running in background<div><p>I did see "This message should be displayed" But I didn't see
command_2 being started.</p>
<p><a href="https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.70">
https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.70</a></p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T21:39:59Z2015-07-27T21:39:59ZIt hangs when there's spawned process running in background<div><p>Aha! Putting everything inside test.cmd worked!! <a href="https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.72">
https://ci.appveyor.com/project/aptxkid/clusterrunner/build/1.0.72</a></p></div>panlu1412tag:help.appveyor.com,2012-11-13:Comment/374759322015-07-27T22:13:05Z2015-07-27T22:13:05ZIt hangs when there's spawned process running in background<div><p>Then you can leave this solution as workaround :)</p>
<ul>
<li>Feodor</li>
</ul></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/374759322017-12-06T15:14:47Z2017-12-06T15:14:49ZIt hangs when there's spawned process running in background<div><p>Just want to note, that this workaround did not work for me, but I found a proper way to start background process that does not halt appveyor pipeline:<br>
<a href="https://stackoverflow.com/a/39175056/644496">https://stackoverflow.com/a/39175056/644496</a></p></div>Mikhail Tymchuk