Sorry, I should have looked at your code more closely in the beginning.
One thing that's important to note is that, every time you call Timer,
you're actually creating a new thread. As such, when you try to call
self.exists(), it seems that it's trying to call a method on the original
object and running into synchronization issues.
In your case, there isn't really a need to use threading.Timer every time
you need an interval; I think instead, you should consider simply creating a
function with an infinite 'while' that periodically polls your renders.
Here's a pseudo-example:
import threading
import time
def postRenderRead(writes, writePaths, startFrame, endFrame):
completed = []
count = len(writes)
pairs = zip(writes, writePaths)
while len(completed) < count:
for w, p in pairs:
if w in completed:
continue
# Poll for complete-ness of `p` here.
# If it's complete, read it in here (using calls to
# nuke.executeInMainThread) and append `w` to
#`completed`.
time.sleep(15)
# Do your cleanup stuff here
t = threading.Thread(None, postRenderRead, args=(writes, [nuke.filename(w)
for w in writes], startFrame, endFrame)
t.start()
It's kind of hacked together, and definitely not as efficient as it could
be, but you get the idea.
-Nathan
-----Original Message-----
From: Jack Simpson
Sent: Thursday, June 21, 2012 7:35 AM
To: nuke-python@support.thefoundry.co.uk
Subject: Re: [Nuke-python] using threading.Timer() to check if files exist
Hi Nathan,
Thanks for your response.
The function I am calling does contain Nuke-specific code.
It reads in the sequences when they are finished rendering (simple loop with
create read node with some values set)
When I render locally and call it with the 'after render' function, it works
fine.
I tried the nuke.executeInMainThread() but to no avail.
def postRenderRead(writes, readnode, startframe, endframe):
for w in writes:
w['selected'].setValue(False)
read = nuke.createNode('Read')
read['file'].setValue(w['file'].getValue())
read['xpos'].setValue(w['xpos'].getValue())
read['ypos'].setValue(w['ypos'].getValue() + 180)
read['format'].setValue(readnode['format'].value())
read['colorspace'].setValue(w['colorspace'].value())
read['first'].setValue(startframe.value())
read['last'].setValue(endframe.value())
read['origfirst'].setValue(startframe.value())
read['origlast'].setValue(endframe.value())
read['selected'].setValue(True)
Thanks again,
Jack
Message: 2
Date: Wed, 20 Jun 2012 15:18:01 -0700
From: Nathan Rusch <nathan_ru...@hotmail.com>
Subject: Re: [Nuke-python] using threading.Timer() to check if files
exist
To: "Nuke Python discussion" <nuke-python@support.thefoundry.co.uk>
Message-ID: <bay153-ds19a27fce9898f2e8a8f012f3...@phx.gbl>
Content-Type: text/plain; charset="utf-8"
Are you calling Nuke-specific code when it crashes? If so, you probably need
to call it using nuke.executeInMainThread(). Give that a try, and if it
doesn’t work, can you post an example of the types of calls you’re making
when it crashes?
-Nathan
From: Jack Simpson
Sent: Wednesday, June 20, 2012 3:13 PM
To: nuke-python@support.thefoundry.co.uk
Subject: [Nuke-python] using threading.Timer() to check if files exist
Hi,
I'm having a problem with the threading.Timer() function.
I've written a little class which runs after I've submitted a job to the
farm.
It checks the directory of the write node(s) to see if the file exists / has
been rendered.
I run the timer to check it every 20 seconds until it completes. It check
nicely every 20 seconds and gives me correct feedback.
However, when it does complete, Nuke crashes and I get an error in the
terminal which includes:
"QObject::setParent" Cannot set parent, new parent is in a different thread"
"QObject::startTimer: QTimer can only be used with threads started with
QThread
"Cannot queue arguments of type 'Animation_Event'"
"Make sure 'Animation_Event' is registered using qRegisterMetaType()"
These errors and crash only occur when the files have finished rendering and
I try to pass another function. Even if I use a try-except.
Here's a simplified snippet of my code:
class PostRender:
def __init__(self, writenodes, args):
get args
print some feedback
self.completed = []
def exists(self):
for w in writes:
if w in self.completed:
continue
if all(framerange in w exists):
print w + ' node has finished rendering'
self.completed.append(w)
else:
print w + ' node is still rendering'
self.wait()
def wait(self):
if len(writenodes) == len(self.completed):
#Crashes here and produces terminal errors
try:
print "Rendering complete"
do another function()
except:
return
else:
myTimer = threading.Timer(15, self.exists())
myTimer.start()
I'm new-ish to Python and have never used the threading module before.
I would be so grateful for any help / light-shedding on this topic.
Thanks,
Jack
Nuke 6.3v3
Windows 7 64bit
16GB RAM
16Core CPU
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python