~ubuntu-branches/ubuntu/trusty/python-eventlet/trusty-proposed

« back to all changes in this revision

Viewing changes to eventlet/patcher.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-03-02 08:57:57 UTC
  • Revision ID: package-import@ubuntu.com-20120302085757-kpasohz8nme655o1
Tags: 0.9.16-1ubuntu2
debian/patches/eventlet-leak.patch: Fixes memory leak in nova. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
        on.setdefault(modname, default_on)
224
224
        
225
225
    modules_to_patch = []
226
 
    patched_thread = False
227
226
    if on['os'] and not already_patched.get('os'):
228
227
        modules_to_patch += _green_os_modules()
229
228
        already_patched['os'] = True
234
233
        modules_to_patch += _green_socket_modules()
235
234
        already_patched['socket'] = True
236
235
    if on['thread'] and not already_patched.get('thread'):
237
 
        patched_thread = True
238
236
        modules_to_patch += _green_thread_modules()
239
237
        already_patched['thread'] = True
240
238
    if on['time'] and not already_patched.get('time'):
266
264
                patched_attr = getattr(mod, attr_name, None)
267
265
                if patched_attr is not None:
268
266
                    setattr(orig_mod, attr_name, patched_attr)
269
 
 
270
 
        # hacks ahead; this is necessary to prevent a KeyError on program exit
271
 
        if patched_thread:
272
 
            _patch_main_thread(sys.modules['threading'])
273
267
    finally:
274
268
        imp.release_lock()
275
269
 
276
 
def _patch_main_thread(mod):
277
 
    """This is some gnarly patching specific to the threading module;
278
 
    threading will always be initialized prior to monkeypatching, and
279
 
    its _active dict will have the wrong key (it uses the real thread
280
 
    id but once it's patched it will use the greenlet ids); so what we
281
 
    do is rekey the _active dict so that the main thread's entry uses
282
 
    the greenthread key.  Other threads' keys are ignored."""
283
 
    thread = original('thread')
284
 
    curthread = mod._active.pop(thread.get_ident(), None)
285
 
    if curthread:
286
 
        import eventlet.green.thread
287
 
        mod._active[eventlet.green.thread.get_ident()] = curthread
288
 
 
289
 
 
290
270
def is_monkey_patched(module):
291
271
    """Returns True if the given module is monkeypatched currently, False if
292
272
    not.  *module* can be either the module itself or its name.