os.execv вызывает ошибку '' OSError: [Errno 12] недостаточно места »' - PullRequest
0 голосов
/ 25 января 2020

Я написал скрипт Python ниже для непрерывной работы. Он предназначен для сканирования моей учетной записи Twilio, и при обнаружении входящих текстовых сообщений он преобразует его в сохраненный текстовый файл. Работает нормально. Однако после 10 часов работы происходит сбой со следующим сообщением об ошибке: Трассировка (последний последний вызов):

  File "messanger.py", line 66, in <module>
    restart()
  File "messanger.py", line 42, in restart
    os.execv(sys.executable, ['python'] + sys.argv)  # Run a new iteration of the current script, providing any command line args from the current iteration.
OSError: [Errno 12] Not enough space

После прочтения документации для os.execv я думаю, что ошибка связана с запуском из-за нехватки памяти Python раз и снова разветвляет скрипт Не уверен, как настроить os.execv, чтобы смягчить это. Возможно, есть более простой подход? Я знаю, что есть что-то простое, что мне не хватает. Я надеюсь, что кто-то в сообществе может помочь.

#importing dependencies
import os
import sys
import datetime
import requests
import json
import time
import re
from twilio.rest import Client
import logging
import os.path
from os import path


def app_run():
    # Your Account SID from twilio.com/console
    account_sid = "XXXXXXXXXXXXX"
    # Your Auth Token from twilio.com/console
    auth_token  = "XXXXXXXXXXXXXXXX"
    client = Client(account_sid, auth_token)
    messages = client.messages.list(to='+############',limit=10)
    logger('message sent')
    try:
        target=messages[0].sid
        message = client.messages(target).fetch()
        body=(message.body)
        from_=(message.from_)
        f = open('../msgs/texter.eam', 'w+')
        f.write(from_+body)
        f.close()
        for record in messages:
            client.messages(record.sid).delete()
    except IndexError:
        logger('exception IndexError handled in app_run')
        time.sleep(3)

def restart():
    print('restarting')
    logger('restart()')
    time.sleep(10)
    #os.fsync()
    os.execv(sys.executable, ['python'] + sys.argv)  # Run a new iteration of the current script, providing any command line args from the current iteration.


def logger(event):
    happend = 'Sucessfully did:'
    logging.debug(happend + event)

#logging setup
try:
    os.remove('../logs/messanger.log')
except:
    f= open('../logs/messanger.log','w+')
    f.close()

logging.basicConfig(filename='../logs/messanger.log', filemode='w', level=logging.DEBUG)
#logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logger('program start')

#luanching the program
i = 0
while i < 100:
    app_run()
    i=i+1
    logger('while loop')
restart()
...