Forums

My long task does not work

import logging import socket import sys

lock_socket = None  # we want to keep the socket open until the very end of
                    # our script so we use a global variable to avoid going
                    # out of scope and being garbage-collected

def is_lock_free():
    global lock_socket
    lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
    try:
        lock_id = "maarcosv99.aovivo"   # this should be unique. using your username as a prefix is a convention
        lock_socket.bind('\0' + lock_id)
        logging.debug("Acquired lock %r" % (lock_id,))
        return True
    except socket.error:
        # socket already locked, task must already be running
        logging.info("Failed to acquire lock %r" % (lock_id,))
        return False

if not is_lock_free():
    sys.exit()

# then, either include the rest of your script below,
# or import it, if it's in a separate file:
from core.crawler import jogoAnaliseAoVivo, jogoAoVivo
while True:
    jogoAnaliseAoVivo()
    jogoAoVivo()
    time.sleep(30)

When executing this script in the terminal it works correctly, without stopping, but when it is executed in the task it simply executes only once and is:

while True:
        jogoAnaliseAoVivo()
        jogoAoVivo()
        time.sleep(30)

does not work

Is the task you are having problems with the hourly task on your account? If so, that command is probably missing a semicolon between the two statements.

Alternatively, see this.

I agree, if there is anything I have learned in the courses I took in 2018, it is that attention to detail is important. So be careful and watch out for the semi colons, dots and everything.