<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic [pymxs] Threading and Modify tab == CRASH in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9680135#M6482</link>
    <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pymxs includes a specific context (mxstoken) that allow us to synchronize calls between different worker threads.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From documentation:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;You cannot call pymxs.runtime commands directly on a worker thread, as this will cause a runtime exception. However, pymxs has a mxstoken() function to support multi-threading by providing a synchronization mechanism between worker threads.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And here and example of its usage:&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_demo_m_x_s_token_8py_example_html" target="_blank"&gt;https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_demo_m_x_s_token_8py_example_html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine, but I have found that 3ds Max crashes if I try to call a function from pymxs.runtime that interacts with 3ds Max modify panel. Super basic code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pymxs
import threading
import time

def callMXSEntry():
    with pymxs.mxstoken():
		pymxs.runtime.modPanel.addModToSelection(pymxs.runtime.Unwrap_UVW())


def main():
    evt = threading.Event()
    t1 = threading.Thread(target=callMXSEntry)
    t1.start()

main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you execute this code, 3ds max will crash (tested in 3ds Max 2018 and 2020).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can imagine that this is happening because that call tries to update Modify Tab UI and 3ds Max UI can only be updated/refreshed in 3ds Max main thread but I'm a not sure about it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know a workaround/solution for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
    <pubDate>Sat, 08 Aug 2020 04:53:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-08-08T04:53:27Z</dc:date>
    <item>
      <title>[pymxs] Threading and Modify tab == CRASH</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9680135#M6482</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pymxs includes a specific context (mxstoken) that allow us to synchronize calls between different worker threads.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From documentation:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;You cannot call pymxs.runtime commands directly on a worker thread, as this will cause a runtime exception. However, pymxs has a mxstoken() function to support multi-threading by providing a synchronization mechanism between worker threads.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And here and example of its usage:&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_demo_m_x_s_token_8py_example_html" target="_blank"&gt;https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_demo_m_x_s_token_8py_example_html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine, but I have found that 3ds Max crashes if I try to call a function from pymxs.runtime that interacts with 3ds Max modify panel. Super basic code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pymxs
import threading
import time

def callMXSEntry():
    with pymxs.mxstoken():
		pymxs.runtime.modPanel.addModToSelection(pymxs.runtime.Unwrap_UVW())


def main():
    evt = threading.Event()
    t1 = threading.Thread(target=callMXSEntry)
    t1.start()

main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you execute this code, 3ds max will crash (tested in 3ds Max 2018 and 2020).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can imagine that this is happening because that call tries to update Modify Tab UI and 3ds Max UI can only be updated/refreshed in 3ds Max main thread but I'm a not sure about it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know a workaround/solution for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Sat, 08 Aug 2020 04:53:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9680135#M6482</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-08T04:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: [pymxs] Threading and Modify tab == CRASH</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695272#M6483</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are sorry for the problems you are experiencing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;During the last year, the 3ds Max team has revisited this topic and concluded that the pymxs.mxstoken() is in fact not a solution for a fundamental design limitation of 3ds Max, which is: the "core" of 3ds Max is not thread safe.&lt;/P&gt;
&lt;P&gt;Therefore, until this underlying limitation is addressed, we have updated the multithreading related topic in our Python documentation to state that pymxs.mxstoken() should be considered deprecated.&lt;/P&gt;
&lt;P&gt;Please see&amp;nbsp;&lt;A href="http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=Max_Python_API_threading_html" target="_blank"&gt;http://help.autodesk.com/view/MAXDEV/2021/ENU/?guid=Max_Python_API_threading_html&lt;/A&gt;&amp;nbsp;for more details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps, and I'm truly sorry for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 14:39:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695272#M6483</guid>
      <dc:creator>attilaszabo</dc:creator>
      <dc:date>2020-08-17T14:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: [pymxs] Threading and Modify tab == CRASH</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695637#M6484</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/86770"&gt;@attilaszabo&lt;/a&gt;&amp;nbsp;thank you so much for the info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another question more or less related with the same topic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doy you know if 3ds Max Python APIs expose any kind of function to force the execution of a function in its main thread?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, Maya exposes this kind of functions&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;executeInMainThreadWithResult.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Thank you so much!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 17:33:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695637#M6484</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-17T17:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: [pymxs] Threading and Modify tab == CRASH</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695689#M6485</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&amp;nbsp;wrote:&lt;P&gt;Doy you know if 3ds Max Python APIs expose any kind of function to force the execution of a function in its main thread?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What is the&amp;nbsp;3ds Max Python API?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Python itself can work in MAX on any thread. But it can only interact with MAX objects (both system and UI) on the main MAX thread. But if you need to do some calculations, for example, using multithreading, you can do it.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 18:01:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695689#M6485</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-08-17T18:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: [pymxs] Threading and Modify tab == CRASH</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695699#M6486</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1634609"&gt;@denisT.MaxDoctor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&amp;nbsp;wrote:&lt;P&gt;Doy you know if 3ds Max Python APIs expose any kind of function to force the execution of a function in its main thread?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What is the&amp;nbsp;3ds Max Python API?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Oh, sorry for the bad usage of the API word here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was referring to MaxPlus and pymxs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 17:55:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/pymxs-threading-and-modify-tab-crash/m-p/9695699#M6486</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-17T17:55:38Z</dc:date>
    </item>
  </channel>
</rss>

