run python in background

run python in background

elpie89
Advocate Advocate
712 Views
1 Reply
Message 1 of 2

run python in background

elpie89
Advocate
Advocate

I'm surely missing something of python or that is already documented in python for 3dsmax 

but how do I execute this code in the background?

import time, threading

WAIT_SECONDS = 1

def foo():
    print(time.ctime())
    threading.Timer(WAIT_SECONDS, foo).start()
    
foo()

 

if I simply run this code in the listener it is executed only one time..

I would expect that print the time every second instead...

I'm probably missing something

0 Likes
713 Views
1 Reply
Reply (1)
Message 2 of 2

MartinBeh
Advisor
Advisor

Not sure this question is still relevant after all this time, but...

I believe threading in Python and 3ds Max is tricky, but you could achieve something like this easily in MAXScript using a "Timer" UI control or using a dotNet call - see this example. And MAXScript can call Python, too.

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes