1

**Updated

I have the following, and according to the example on the pyudev readthedocs site, it should be daemon threaded. However, even coupling it with Threading, it blocks when using eventlet's monkey patching.

from threading import Thread
from pyudev import Context, Monitor, MonitorObserver

import eventlet
eventlet.monkey_patch()

def useless_thread():
    while True:
        print 'sleep thread 1'
        time.sleep(2)

# Monitor UDEV for drive insertion / removal
def disk_monitor_thread():
    context = Context()
    monitor = Monitor.from_netlink(context)
    monitor.filter_by('block')
    def print_device_event(action, device):
        if 'ID_FS_TYPE' in device and device.get('ID_FS_UUID') == '123-UUIDEXAMPLE':
            print('{0}, {1}'.format(device.action, device.get('ID_FS_UUID')))
    print 'Starting Disk Monitor...'
    observer = MonitorObserver(monitor, print_device_event, name='monitor-observer')
    print 'Disk Monitor Started'
    observer.start()

t1 = Thread(name='uselessthread', target=useless_thread)
t1.start()
disk_monitor_thread()

Runs this:

sleep thread 1
'Disk Monitor Started'

I'm using eventlet's monkey patching for Flask-SocketIO, which is causing useless_thread1() to stop firing. If I comment out the monkey patch call, all works as intended.

Kenny Powers
  • 1,254
  • 2
  • 15
  • 25
  • 1
    I ran it without threading and it doesn't seem to block: http://lpaste.net/174029 – ErikR Aug 04 '16 at 03:28
  • Interesting, I just did the same...removed the threading calls and it did not block. Is this because MonitorObserver is asynchronous? – Kenny Powers Aug 04 '16 at 21:05
  • It appears that `MonitorObserver` starts a thread of its own. You can use `observer.stop()` to stop that thread. [(link)](http://pyudev.readthedocs.io/en/latest/api/pyudev.html#pyudev.MonitorObserver.send_stop) – ErikR Aug 04 '16 at 21:14
  • 1
    So it looks like my problem is the combination of this with other threads. I'm using threading.Thread() to run a Flask Weurkzeug and handle a couple of other flask-socketio responses. When I use MonitorObserver in conjunction with any of it the other threads appear to lock. – Kenny Powers Aug 04 '16 at 21:19
  • Any solution? I am running into the same problem – Jake Feb 08 '17 at 21:52
  • No. I went with another method to solve the problem. Sorry. – Kenny Powers Feb 12 '17 at 23:36

0 Answers0