2

I have an application that allows you to use a Python startup script. I want to run one part of the code after the application is fully initialized, but there is no way to know this.

I used time.sleep() but then the application hangs till it executes that code. I also transferred the code to another file and used execfile but same result.

So basically I want something like this:

startup script:
    my code
    code to run 5 seconds later

What's the easiest way to achieve this? Do I have to use threading for this?

5
  • What application are you using? Commented Feb 6, 2015 at 2:32
  • Maya 3d application. Commented Feb 6, 2015 at 2:34
  • I think threading is the easiest way: stackoverflow.com/questions/16691576/… Commented Feb 6, 2015 at 4:10
  • @ZZY: I actually tried this an hour ago but it still blocks it when I use sleep in the other method. I don't know why that's not concerned by its own thread but I assume maybe the app itself is encapsulating everything to run in a single thread? Commented Feb 6, 2015 at 4:31
  • 1
    Maybe you can try executeInMainThreadWithResult or executeDeferred. I don't have Maya environment to test Commented Feb 6, 2015 at 8:06

1 Answer 1

1

How about at the end of your startup script it writes to or creates a log file contains something like 'initiation complete'.

So another code will check if the file is created or the text is written after each x millisecond and then execute the rest of it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but who will run that code that checks for the file? Because if I start it and then that code hangs till the file is written, the app will still hang till then.
@JoanVenge, you can throw the loop check for the log file to another thread or process, so the rest of your program will run without being blocked.
Thanks I tried the thread thing but it didn't work. I will research the process thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.