0

Whenever I use eventlet's monkey patching (necessary for Flask-SocketIO) the disk_monitor_thread() prevents other threads from firing. Eventlet and monkey patching is a must for me. Is there a way to get pyudev's MonitorObserver to place nice and release the GIL with 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()

results in:

sleep thread 1
Starting Disk Monitor...

and never moves forward from there

Kenny Powers
  • 1,254
  • 2
  • 15
  • 25
  • Flask-SocketIO does not require monkey patching when using eventlet. It is typically the application that does. Have you tried running without monkey patching, assuming your application is fine with it? – Miguel Grinberg Sep 11 '16 at 02:20
  • And also, as [recommended in the eventlet docs](http://eventlet.net/doc/patching.html#monkeypatching-the-standard-library) see if moving the monkey patching statements above the other imports help. – Miguel Grinberg Sep 11 '16 at 02:28

0 Answers0