0

I have two files in the same directory, A module has a function that is continously running and has no way to stop or pause in between,

# script.py
def run():
    i = 0
    while True:
        print('\r', i, '\r', end='')
        i += 1
    

Then there is a custom made debugger module which captures if the directory has been updated,

# debugger.py
import os
import wait
from multiprocessing import Process, Queue

def capture_change(processesQueue):
    prev = os.path.getsize('wait.py')
    while True:
        curr = os.path.getsize('wait.py')

        if curr != prev:
            print('Changes Detected!!')
            process = processesQueue.get()
            process.kill()
            process.start()
            processesQueue.put(process)
        
        prev = curr

if __name__ == "__main__":
    processesQueue = Queue()
    p1 = Process(target= wait.run)
    processesQueue.put(p1)
    p2 = Process(target= capture_change, args= (processesQueue, ))

    p1.start()
    p2.start()

I am getting this error,

    raise TypeError(
TypeError: Pickling an AuthenticationString object is disallowed for security reasons

What should I do? I have searched alot but all the ways for data sharing among other processes are not allowing Process instance itself to be shared among them. Is there any other way around??

  • 2
    The choice to block process objects from being pickled was a conscious decision to avoid security vulnerabilities. Cleanup of the child processes should be happening in the parent process which created it. Why not have `capture_change` be called in the parent process? – flakes Jun 15 '22 at 22:05
  • 1
    Yeah it worked flawlessly. Thanks a lot. – Aman Ahmed Siddiqui Jun 16 '22 at 13:23

1 Answers1

0

Thanks to @flakes I have finally got a way around the part I was hoping to achieve,

# debugger.py
import os
from multiprocessing import Process


def capture_change(processesQueue):
    prev = os.path.getsize('wait.py')
    import wait
    process = Process(target= wait.run)
    process.start()
    while True:
        curr = os.path.getsize('wait.py')

        if curr != prev:
            import wait
            print('Changes Detected!!')
            if process.is_alive():
                process.kill()
            process = Process(target= wait.run)
            process.start()
        
        prev = curr

if __name__ == "__main__":
    capture_change_and_reload()

This is my final code that works as required.