2010/10/23 Merlijn van Deen <[email protected]>

> On 23 October 2010 12:13, Bináris <[email protected]> wrote:
>
>> quitting with "q". Not applicable with ctrl C. Here is a little bug, the
>> counter cannot check if put_async _will_ be successful.
>>
>
> It can.
>
>     def put_async(self, newtext,
>                   comment=None, watchArticle=None, minorEdit=True, 
> force=False,
>                   callback=None):
> (...)
>         callback: a callable object that will be called after the page put
>                   operation; this object must take two arguments:
>                   (1) a Page object, and (2) an exception instance, which
>                   will be None if the page was saved successfully.
>
> Just make sure you know how to do multithreading, or this will come back
> to bite you. (No, incrementing a global variable is not the right way.)
>

I tried to learn and read this threading stuff in order to have a correct
editcounter. (If was quite a time ago, so someone might forget the topic: 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

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
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?

3rd test: I created an edit conflict with the same result. (I made the bot
to write err instead of 9999999, it's OK.)

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
First, the error is not handled, second, callback got None for error and
reported a false success.


-- 
Bináris
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l

Reply via email to