python线程出错

时间:2016-03-05 20:21:48

标签: python python-2.7 tweepy

我尝试在我的脚本中使用thread,但是我收到了这个错误:

  

缺少sys.excepthook启动的线程中的未处理异常   丢失了sys.stderr

我的剧本:

# -*- coding: utf-8 -*-

import tweepy
import thread

consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""


def deleteThread(api, objectId):
    try:
        api.destroy_status(objectId)
        print "Deleted:", objectId
    except:
        print "Failed to delete:", objectId

def oauth_login(consumer_key, consumer_secret):
    """Authenticate with twitter using OAuth"""

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth_url = auth.get_authorization_url()

    verify_code = raw_input("Authenticate at %s and then enter you verification code here > " % auth_url) 
    auth.get_access_token(verify_code)

    return tweepy.API(auth)

def batch_delete(api):
    print "You are about to Delete all tweets from the account @%s." % api.verify_credentials().screen_name
    print "Does this sound ok? There is no undo! Type yes to carry out this action."
    do_delete = raw_input("> ")
    if do_delete.lower() == 'yes':
        for status in tweepy.Cursor(api.user_timeline).items():
            try:
                thread.start_new_thread( deleteThread, (api, status.id, ) )
            except:
                print "Failed to delete:", status.id

if __name__ == "__main__":
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)
    print "Authenticated as: %s" % api.me().screen_name

    batch_delete(api)

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

<强>更新

  

我只是在

之前添加$(function () { $('input[type="redditSearch"]').on('change', function () { var $clone = $(".redditContainer").eq(0).clone().appendTo("#redditMain"); $clone.attr('id',$clone.attr('id').replace(/\d+$/, function(str) { return parseInt(str) + 1; }) ); $clone.find('[id]').each(function() { var $th = $(this); var newID = $th.attr('id').replace(/\d+$/, function(str) { return parseInt(str) + 1; }); $th.attr('id', newID); }) } //Error appears to be here loadRedditData($(this).val()); }); }); 来解决我的问题      

$(function () { $('input[type="redditSearch"]').on('change', function () { var $clone = $(".redditContainer").eq(0).clone().appendTo("#redditMain"); $clone.attr('id',$clone.attr('id').replace(/\d+$/, function(str) { return parseInt(str) + 1; }) ); } loadRedditData($(this).val()); }); });