I created an editcounter in class ReplaceRobot of replace.py and was
disappointed with my counter not listening to the failure of put_async.
Now I created a callback function:
def lacika(self, page, err):
if err is None:
print u'%s saved successfully' % page.title() #for debug
else:
print 9999999
self.editcounter -= 1
print self.editcounter
Note that this is not thread safe (or maybe it is due to the GIL - but it
could happen self.editcounter changes between reading it, subtracting one,
and writing it back).
Now I ran four tests:
1. Successful save, it's OK.
2. After loading the page, while replace.py waits for my choice, I
protected the page. Result:
1 page was changed. <-- message from main process
Updating page [[Szerkesztő:BinBot/semmi]] via API
9999999 <-- just a test message from callback
0 <-- New self.editcounter, correct, but too late
What is exactly the problem here? This is exactly the expected behaviour:
it runs the callback /after/ the page has been saved. It's not a time
machine. If you need to have an exact editcount during the main loop, use
.put(). Alternatively, move your logic into the callback function - that is
the only place where the correct information is available.
Here comes my first problem. As far as I understood, I
should use *join*to make the main process wait for put_async. But put_asyn is taken from
wikipedia.py. How can I use *join* here, where should I write it? Could
someone write a simple example to make the bot wait for put_async?
Why would you want to join() the thread? The bot always waits for all save
operations to finish.
4th test: After loading the page, while the bot is
waiting for my choice,
I delete the page. This seems to be a bug:
1 page was changed.
Updating page [[Szerkesztő:BinBot/semmi]] via API
Unknown Error. API Error code:missingtitle
Information:The article you tried to edit doesn't exist
Szerkeszt<:BinBot/semmi saved successfully
So did it re-create the page? or...?
Best,
Merlijn