Running a Loop in background Along with normal Krita Session

from krita import *
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import (QEventLoop, QTimer)
import os
_info = InfoObject()
running = False

def getPath(fullPath):
    for x in range (0,len(fullPath)):
        arrayIndex = len(fullPath)-x-1
        currentChar = fullPath[arrayIndex]
    
        if currentChar == '/':
            path = fullPath[0:arrayIndex+1]
            return path

def SaveFile(name,number):
    Krita.instance().activeDocument().setBatchmode(True)
    Krita.instance().activeDocument().exportImage(name+str(number)+".jpeg",_info)
    Krita.instance().activeDocument().setBatchmode(False)

def sleep(value):
    loop = QEventLoop()
    QTimer.singleShot(value, loop.quit)
    loop.exec()


def Start(name,delay, instance):
    path = getPath(Krita.instance().activeDocument().fileName())
    if os.path.isdir(path+"CrudeTimelapse/")==False:
        os.mkdir(path+"CrudeTimelapse/")
    finalPath = path + "CrudeTimelapse/" + name + ".jpeg"
    i=0
    running = True
    while(running):
        #Debug stuff OPEN
        if instance==True:
            if i>10:
                running = False
        #DebugStuff CLOSE

        #god please forgive me for this
        if Krita.instance().activeDocument().framesPerSecond() == 1:
            running = False
        
        i+=1
        SaveFile(finalPath,i)
        sleep(delay*1000)
        QApplication.instance().processEvents()
        
    
#Start("meh2",10,True)

So I’m done with this and it serves my purpose lol
i can finally get back to working.

if u find any bruteforcing (like how to stop the recording process)
please forgive, i started with python literally a month ago, and all my experience has been in bpy so far
My drawing sessions are usually 12-24 hours so i guess a 10-30 sec delay works, also, not really getting any performance issues at 1080p, so i guess its kinda okayish for now

Unfortunately it skips export when the brush is drawing on the canvas, which can or cannot be an issue, I’ll try and see how that goes

anyways, Thanks a lot for your help :smile: