xybu / onedrive-d-old

Microsoft OneDrive client on Linux.
http://xybu.me/projects/onedrive-d/
GNU Lesser General Public License v3.0
820 stars 143 forks source link

Is cleanup in od_mon_cli thread-safe? #181

Open starrwang opened 8 years ago

starrwang commented 8 years ago

Hi, I have made a simple experiment like below (I'm sorry you might have to re-edit the indents before running it), I found deadlock when I send 'kill -15 pid' , I have to send 'kill -9 pid' to terminate it. So I have a little bit worry about the atexit handler usage in od_mon_cli.Monitor.

import threading import time import signal import sys import atexit

lock = threading.Lock()

def handle_atexit():

dangeous when someone in same thread holding the lock!!

lock.acquire()
print "acquire lock in exit callback!"
lock.release()

def do_exit(x,y): sys.exit(0)

atexit.register(handle_atexit) signal.signal(signal.SIGTERM, do_exit)

def non_release(): lock.acquire() while True: time.sleep(1) print "i'm having lock!" lock.release() ## outside of while loop

non_release()