第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Lambda + Python + 退出代碼

Lambda + Python + 退出代碼

猛跑小豬 2021-07-09 18:11:35
我遇到了一個用 Python 編寫的簡單 AWS Lambda 函數(shù)的問題。當我運行我的 Lambda 函數(shù)時,我的代碼按預期運行,結(jié)果是正確的,但仍然以錯誤代碼(退出代碼): 結(jié)束"Process exited before completing request",這導致 Lambda 運行 3 次(異步)。您是否有任何最佳實踐來管理 Lambda 的退出代碼?#!/usr/bin/pythonimport boto3import sysimport tweepyimport datetimesession = boto3# Init s3 clients3 = session.resource('s3')def get_data_and_push(s3_bucket, s3_key, user):    # Retrieve CSV file    try:        dest = s3.Object(s3_bucket, s3_key)        dest.download_file(tmpfile)    except Exception, e:        print 'An error occured while trying to download CSV file'        print 'This exception has been thrown :'        print e        sys.exit(1)    # Authenticate to Twitter    try:        auth = tweepy.OAuthHandler(t_consumer_key, t_consumer_secret)        auth.set_access_token(t_access_token_key, t_access_token_secret)        api = tweepy.API(auth)    except Exception, e:        print 'Cannot authenticate to Twitter.'        print 'This exception has been thrown :'        print e        sys.exit(2)    data = api.get_user(user)    print 'User : ' + data.screen_name    print 'Followers : ' + str(data.followers_count)    print 'Friends : ' + str(data.friends_count)    print '-----------'    # Get today's date    today = datetime.datetime.now().strftime("%Y-%m-%d")    # Write result    try:        # Write result at the end of the file        file = open(tmpfile, 'a')        file.write(today + ',' + str(data.followers_count) + ',' + str(data.friends_count)+ '\n')        file.close()    except Exception, e:        print 'Unable to write in temp file'        print 'This exception has been thrown :'        print e        sys.exit(5)    # Upload final file    try:        # Push file to S3        dest.upload_file(tmpfile)    except Exception, e:        print 'An error occured while trying to upload CSV file'        print 'This exception has been thrown :'        print e        sys.exit(6)謝謝你的幫助,
查看完整描述

1 回答

?
慕無忌1623718

TA貢獻1744條經(jīng)驗 獲得超4個贊

短的

是的,刪除sys.exit(0)代碼末尾的 ,應該這樣做:-)


更長

通過這樣做,sys.exit(0)您實際上會停止在 Lambda 函數(shù)中運行您的代碼的進程。這不是執(zhí)行者所期望的。

我假設 Lambda 函數(shù)的處理程序?qū)嶋H上是在 AWS 的框架內(nèi)運行的。因此,您已經(jīng)在一個 python 進程中,并且您的處理程序在 AWS 代碼中的某處被調(diào)用。所以如果你退出這個過程,你實際上是在走捷徑AWS的框架,它無法處理Lambda執(zhí)行的解析。


查看完整回答
反對 回復 2021-07-13
  • 1 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號