<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Форум QUIK [тема: Почему умерает корутина?]</title>
		<link>http://forum.quik.ru</link>
		<description>Новое в теме Почему умерает корутина? форума  на сайте Форум QUIK [forum.quik.ru]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Thu, 09 Apr 2026 13:26:27 +0300</pubDate>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3959/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Да, Николай, здравствуйте. <br />Я понял уже что появление события рубит мой поток или как его назвать.. Хотел сделать скрипт изящнее, с использованием возможностей клуа, но, из-за того что я не программист, пришлось приводить архитектуру к обычному синхронному языку. События дополняют таблицы и все. А скрипт по этим таблицам в нужное время работает. Понимаю, что получился велосипед на платформе машины, но только так смог добиться устойчивой работы. <br />
			<i>28.04.2015 13:30:03, Viktor MMM.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3959/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3959/topic442/</guid>
			<pubDate>Tue, 28 Apr 2015 13:30:03 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3870/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<noindex><a href="https://forum.quik.ru/user/738/" target="_blank" rel="nofollow">Viktor MMM</a></noindex><br />Попробуйте рассмотреть работу Вашей программы, <br />когда приходят onorder, а корутина еще занята обработкой предыдущего.<br />-----------------------------------------<br />Для использования корутины с колбеками надо делать очередь. <br />
			<i>25.04.2015 13:43:04, Николай  Камынин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3870/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3870/topic442/</guid>
			<pubDate>Sat, 25 Apr 2015 13:43:04 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3748/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_HkXSHTLQ" href="/user/137/" bx-tooltip-user-id="137">
sam063rus</a>, да, я его переделал. Вынес создание за цикл, резюмировал в итоге только тогда когда статус - dead. <br />Вот сейчас это выглядит так: (то, что относится к корутине)<br /><br />
====code====
<pre>function OnOrder(trans_order)
PrintDbgStr("В онордере прошло событие flag ="..tostring(flag))
PrintDbgStr("статус в онордере " .. tostring(coroutine.status(co)))
--if coroutine.status(co) == "running" then coroutine.resume(co) end
&nbsp;&nbsp;&nbsp;if flag and trans_order&#91;"sec_code"&#93; == SECCODE and trans_order&#91;"brokerref"&#93; == COMMENT_ALL and trans_order&#91;"class_code"&#93; == CLASSCODE then 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.sinsert(ORDER_TABLE,1,trans_order) 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintDbgStr("Прошли по условию в онордер")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flag = false
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--if coroutine.status(co) == "normal" or coroutine.status(co) == "suspended" then coroutine.resume(co) end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coroutine.resume(co)
&nbsp;&nbsp;&nbsp;end
end
 </pre>
=============
закомментированы разные варианты, я пробую то так то эдак.. Flag, что бы при двойном подтверждении два раза не срабатывал резюм.<br /><br /><br />
====code====
<pre>function bots()
&nbsp;&nbsp;&nbsp;PrintDbgStr("В BOTS скрипте даем команду на продажу")
&nbsp;&nbsp;&nbsp;PrintDbgStr(tostring(coroutine.status(co)))
&nbsp;&nbsp;&nbsp;--_SellOpt(TRID_TRADE,2000,QTY,MODE,COMMENT_ALL)
&nbsp;&nbsp;&nbsp;flag = true
&nbsp;&nbsp;&nbsp;_SellOpt(TRID_TRADE,2000,QTY,MODE,COMMENT_ALL)
&nbsp;&nbsp;&nbsp;PrintDbgStr("BOTS залип после продажи")
&nbsp;&nbsp;&nbsp;coroutine.yield()
&nbsp;&nbsp;&nbsp;PrintDbgStr("BOTS отлип после продажи")
&nbsp;&nbsp;&nbsp;--sleep (5000)
&nbsp;&nbsp;&nbsp;PrintDbgStr("приступаем к удалению")
&nbsp;&nbsp;&nbsp;PrintDbgStr(tostring(coroutine.status(co)))
&nbsp;&nbsp;&nbsp;--sleep(1000)
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;num2 = _GetActiveOrdersNum()&#91;1&#93;
&nbsp;&nbsp;&nbsp;PrintDbgStr("Выставлена заявка №".. tostring(num2))
&nbsp;&nbsp;&nbsp;flag = true
&nbsp;&nbsp;&nbsp;_KillOrder(num2,TRID_KILL)
&nbsp;&nbsp;&nbsp;PrintDbgStr("BOTS залип после удаления")
&nbsp;&nbsp;&nbsp;coroutine.yield()
&nbsp;&nbsp;&nbsp;PrintDbgStr("BOTS отлип после удаления")
&nbsp;&nbsp;&nbsp;--coroutine.resume(co)
end

is_run=true
flag = true


PrintDbgStr(COMMENT_ALL..": Инициализация прошла")
co = coroutine.create(bots)

function main( ... )
first = true


PrintDbgStr(tostring(coroutine.status(co)))
&nbsp;&nbsp;&nbsp;while is_run do&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintDbgStr("В основном скрипте пошел прогон")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintDbgStr(tostring(coroutine.status(co)))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if first then coroutine.resume(co)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first = false
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if coroutine.status(co) == "dead" then 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;co = coroutine.create(bots)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintDbgStr(tostring(coroutine.status(co)))

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(200)
&nbsp;&nbsp;&nbsp;end

end
 </pre>
=============
и лог в итоге:<br /><table class="forum-spoiler"><thead onclick="if (this.nextSibling.style.display=='none') { this.nextSibling.style.display=''; BX.addClass(this, 'forum-spoiler-head-open'); } else { this.nextSibling.style.display='none'; BX.removeClass(this, 'forum-spoiler-head-open'); } BX.onCustomEvent('BX.Forum.Spoiler:toggle', [{node: this}]); event.stopPropagation();"><tr><th><div>Скрытый текст</div></th></tr></thead><tbody class="forum-spoiler" style="display:none;"><tr><td>00000001 &nbsp; &nbsp;0.00000000 &nbsp; &nbsp;&#91;9384&#93; SR6500BF5//SCRYPT: Инициализация прошла &nbsp; &nbsp;<br />00000002 &nbsp; &nbsp;0.00055721 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000003 &nbsp; &nbsp;0.00062351 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000004 &nbsp; &nbsp;0.00070361 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000005 &nbsp; &nbsp;0.00077565 &nbsp; &nbsp;&#91;9384&#93; В BOTS скрипте даем команду на продажу &nbsp; &nbsp;<br />00000006 &nbsp; &nbsp;0.00083352 &nbsp; &nbsp;&#91;9384&#93; running &nbsp; &nbsp;<br />00000007 &nbsp; &nbsp;0.00097225 &nbsp; &nbsp;&#91;9384&#93; SR6500BF5//SCRYPT: Проверка цены на существенный выход. Цена в установленных пределах _VerifyPriceToTheor(price,direction) &nbsp; &nbsp;<br />00000008 &nbsp; &nbsp;0.00130182 &nbsp; &nbsp;&#91;9384&#93; SR6500BF5//SCRYPT: Отправляю команду в терминал на Продажу _SellOpt(trid,price,qty,mode,comment) &nbsp; &nbsp;<br />00000009 &nbsp; &nbsp;0.00482790 &nbsp; &nbsp;&#91;9384&#93; BOTS залип после продажи &nbsp; &nbsp;<br />00000010 &nbsp; &nbsp;0.00490033 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000011 &nbsp; &nbsp;0.20509318 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000012 &nbsp; &nbsp;0.20515488 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000013 &nbsp; &nbsp;0.20520814 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000014 &nbsp; &nbsp;0.36994475 &nbsp; &nbsp;&#91;9384&#93; В онордере прошло событие flag =true &nbsp; &nbsp;<br />00000015 &nbsp; &nbsp;0.37005705 &nbsp; &nbsp;&#91;9384&#93; статус в онордере suspended &nbsp; &nbsp;<br />00000016 &nbsp; &nbsp;0.37009996 &nbsp; &nbsp;&#91;9384&#93; Прошли по условию в онордер &nbsp; &nbsp;<br />00000017 &nbsp; &nbsp;0.37016127 &nbsp; &nbsp;&#91;9384&#93; BOTS отлип после продажи &nbsp; &nbsp;<br />00000018 &nbsp; &nbsp;0.37022066 &nbsp; &nbsp;&#91;9384&#93; приступаем к удалению &nbsp; &nbsp;<br />00000019 &nbsp; &nbsp;0.37028122 &nbsp; &nbsp;&#91;9384&#93; running &nbsp; &nbsp;<br />00000020 &nbsp; &nbsp;0.37132820 &nbsp; &nbsp;&#91;9384&#93; В онордере прошло событие flag =false &nbsp; &nbsp;<br />00000021 &nbsp; &nbsp;0.37138492 &nbsp; &nbsp;&#91;9384&#93; статус в онордере dead &nbsp; &nbsp;<br />00000022 &nbsp; &nbsp;0.40539524 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000023 &nbsp; &nbsp;0.40549716 &nbsp; &nbsp;&#91;9384&#93; dead &nbsp; &nbsp;<br />00000024 &nbsp; &nbsp;0.40567231 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000025 &nbsp; &nbsp;0.60553598 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000026 &nbsp; &nbsp;0.60559422 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000027 &nbsp; &nbsp;0.60565478 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000028 &nbsp; &nbsp;0.80577093 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000029 &nbsp; &nbsp;0.80582190 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000030 &nbsp; &nbsp;0.80587631 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000031 &nbsp; &nbsp;1.00597680 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000032 &nbsp; &nbsp;1.00604546 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000033 &nbsp; &nbsp;1.00611746 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000034 &nbsp; &nbsp;1.21077490 &nbsp; &nbsp;&#91;9384&#93; В основном скрипте пошел прогон &nbsp; &nbsp;<br />00000035 &nbsp; &nbsp;1.24667192 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />00000036 &nbsp; &nbsp;1.26349628 &nbsp; &nbsp;&#91;9384&#93; suspended &nbsp; &nbsp;<br />.<br />.<br />.<br />.<br />00000085 &nbsp; &nbsp;4.54232550 &nbsp; &nbsp;&#91;9384&#93; SR6500BF5//SCRYPT: Скрипт остановлен пользователем</td></tr></tbody></table>вот это место:<br /><br />00000017 &nbsp; &nbsp;0.37016127 &nbsp; &nbsp;&#91;9384&#93; BOTS отлип после продажи &nbsp; &nbsp;<br />00000018 &nbsp; &nbsp;0.37022066 &nbsp; &nbsp;&#91;9384&#93; приступаем к удалению &nbsp; &nbsp;<br />00000019 &nbsp; &nbsp;0.37028122 &nbsp; &nbsp;&#91;9384&#93; running &nbsp; &nbsp;<br />00000020 &nbsp; &nbsp;0.37132820 &nbsp; &nbsp;&#91;9384&#93; В онордере прошло событие flag =false &nbsp; &nbsp;<br />00000021 &nbsp; &nbsp;0.37138492 &nbsp; &nbsp;&#91;9384&#93; статус в онордере dead &nbsp; &nbsp;<br /><br />с чего вдруг когда отлипает BOTS, скрипт проходит дальше,статус руннинг, и как заходит в num2 = _GetActiveOrdersNum()&#91;1&#93;, появляется событие в онордере, flag пустить не должен на резюм, а статус уже DEAD. Что может два раза резюмировать или даже три!!! чтобы корутина померла так досрочно.. <br />
			<i>24.04.2015 12:54:12, Viktor MMM.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3748/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3748/topic442/</guid>
			<pubDate>Fri, 24 Apr 2015 12:54:12 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3740/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			не особо разбирал ваш пример в соседней ветке - бо как там всё надо переделывать, но что бросается в глаза: у вас в майне создаётс thread-объект "co". Причём каждый цикл майна создаёт/затирает предыдущий объект корутины. Причё, это всё абсолютно никак у вас не синхронизировано с resume из коллбеков. То есть получается, что код становится абсолютно неуправляемым и LUA непонимает какой именно объект запускать или приостанавливать в каждый момент времени. бо как указано выше, у вас одна и таже переменная создаётся/используется в цикле. <br />
			<i>24.04.2015 12:15:47, sam063rus.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3740/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3740/topic442/</guid>
			<pubDate>Fri, 24 Apr 2015 12:15:47 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3737/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Здравствуйте,<br />К сожалению, затруднюсь назвать причины. <br />Возможно что то делаете не так.<br />В соседней ветке, Вам рекомендовали для ознакомления статьи по теме корутинов. <br />
			<i>24.04.2015 11:49:52, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3737/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3737/topic442/</guid>
			<pubDate>Fri, 24 Apr 2015 11:49:52 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Почему умерает корутина?</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message3692/topic442/">Почему умерает корутина?</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Есть функция, вызывается как корутина. <br />В ней две остановки - после выставления ордера и после снятия ордера.<br />в трансрепли (или в ордеррепли - не важно) стоит разрешение работать дальше.<br />Первая остановка проходит нормально, заявка выставляется. <br />Пока корутина не начала работать её статус - suspended<br />начала - running<br />когда выполняем первый останов статус - suspended<br />транзрепли его отлепляет и статус становится опять running<br />тут все понятно, все логично так и быть должно<br /><br />но, когда в функции начинает исполнятся другая функция (это единственное наблюдение) статус моей корутины - dead. <br />А я еще не дошел до второй остановки даже. Не с чего ей останавливаться по завершению. Я ведь правильно понимаю, что dead - значит завершена? или я не прав? <br />
			<i>23.04.2015 19:57:20, Viktor MMM.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message3692/topic442/</link>
			<guid>http://forum.quik.ru/messages/forum10/message3692/topic442/</guid>
			<pubDate>Thu, 23 Apr 2015 19:57:20 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
	</channel>
</rss>
