Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Python for Unity - Threading

Discussion in 'Formats & External Tools Previews' started by mdooneymill, Jun 21, 2021.

  1. mdooneymill

    mdooneymill

    Joined:
    Feb 7, 2019
    Posts:
    9
    Apologies if this has been covered before but I couldn't find an answer anywhere.

    Does Unity support threading in Python?
    I've got a PySide2 interface which relies on a bunch of web queries and I'm trying to move those off the main thread so that the UI doesn't freeze.

    Using QThread I find that the thread never executes and when using QRunnable the editor crashes. Just wondering if I've missed something obvious somewhere or whether it's just not supported yet.

    Cheers,

    Mark
     
  2. bhudson

    bhudson

    Joined:
    Nov 21, 2014
    Posts:
    31
    Just to be clear, you're on Python 4.0.0-exp.1 right?

    All calls to Unity or to any C# code must be done on the main thread -- even if you just `import` a module implemented in C#, it needs to be imported on the main thread. Otherwise the editor can crash or hang indefinitely.

    Other than that, it's supposed to work to have threads that are entirely in the Python universe doing their thing; indeed the PySide sample has multiple threads.
     
    mdooneymill likes this.