I
I
InternetMaster2021-10-20 23:15:44
Python
InternetMaster, 2021-10-20 23:15:44

Multithreading not working?

Question: I use threading for multithreading, but then a problem arose that the multithreading should solve, but it did not disappear. The question is that the code does not continue to be executed, although multithreading is used.

Here is the code itself:

def egz_checkden():
    svv = sqlite.GetInfo()
    svv.get_okdata()
    itt = sqlite.itt
    d = datetime.now()
    date = d.strftime('%d.%m.%Y')
    print(221)
    for x in itt:
        if x[4] < date:
            svv.useer_id = x[1]
            svv.udal_subs()
            with open(os.path.abspath(os.getcwd()) + '\HistorySubs\\' + x[1] + '.txt', 'a+') as file:
                if x[5] == '0':
                    file.write(f'User ID: {x[1]}\nUsername: {x[2]}\nData Start: {x[3]}\nData End: {x[4]}\nProdlen: No\nLimit: {x[7]}\n\n')
                    file.close()
                else:
                    file.write(f'User ID: {x[1]}\nUsername: {x[2]}\nData Start: {x[3]}\nData End: {x[4]}\nProdlen: Yes\nKolvo Prodlen: {x[6]}\nLimit: {x[7]}\n\n')
                    file.close()
    time.sleep(86400)
    egz_checkden()
Thread(target=egz_checkden(), args=())
chckden.start()
print('OK!') # Тут код уже не работает

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vindicar, 2021-10-20
@Vindicar

Thread(target=egz_checkden () , args=())
When pogromists already learn to distinguish between the result of a function call (with brackets) and a function reference (without brackets).
You now have Python trying to egz_checkden() to get its return value and use it as the target.
And yes, you have an infinite recursion in egz_checkden(), albeit a slow one. Will crash on stack overflow, although not immediately. Don't do that, use a normal loop.

M
mkone112, 2021-10-20
@mkone112

It seems to me that everything should work ... um ... as it should. Why did you decide that it should reach print?

J
javedimka, 2021-10-20
@javedimka

Thread(target=egz_checkden(), args=())
in target it is necessary to pass the object of the function, and not the result of its execution
Thread(target=egz_checkden, args=())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question