0

Hi. im trying to append a text file that is created by another class via another class which are threads.

for example, i have :

class AClass(QThread):
    def run(self):
        with open("Log.txt", "w") as h:
            h.write("Blabla \n")

class BClass(QThread):
    def run(self):
        with open("Log.txt", "a") as t:
            t.write("new line of txt \n")

However, when BClass doesn't append the new line. but if its a new file say "LogF.txt" it will append to that new file. I tried using a+ too but no go. im assuming because they are running at the same time or smtg like that so BClass can't append to Log.txt because to BClass that file doesn't exist? How would i get around that? theres a function, isAlive() but i think my googling skills are weak coz i can't find any sort of documentation about it, so im not sure how to use it or if it will resolve my issue. Any help is greatly appreaciated.

2
Contributors
1
Reply
17
Views
4 Months
Discussion Span
Last Post by woooee
0

Have BClass write to a separate file and combine them when the threads have finished. You could also use a thread safe SQL server, like MariaDB/MySql, but not SQLite.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.