Skip to content

Instantly share code, notes, and snippets.

;;; cwc.el --- whitespace-cleanup only for changed lines
;;
;; Author: Ralf Schmitt <ralf@systemexit.de>
;; Version: 0.1
;; Last Changed: 2010-04-13 17:03:32 by ralf
;;; Commentary:
;;
;; run whitespace-cleanup only on changed lines in a buffer. needs
;; highlight-changes mode to do it's work.
# Last-changed: 2010-07-29 00:39:14 by ralf
"""
this module installs a custom __import__ function, which switches
sys.modules on a per-thread basis. patch_all must be called from the
gevent thread. the threads will only import unpatched modules.
"""
import imp, sys, threading
#! /usr/bin/env python
import sys, os, signal, getopt, time
base_cgroup = "/cgroup"
def get_pids(name):
pids = open(os.path.join(base_cgroup, name, "tasks")).read().split()
return pids
@schmir
schmir / s.py
Created September 7, 2010 21:22
#!/usr/bin/env python
# only works with patched gevent from http://github.com/schmir/gevent
from gevent import tlmonkey
tlmonkey.patch_all()
import gevent
from gevent import tpool
import sys
diff --git a/gevent/greenlet.py b/gevent/greenlet.py
index 93076db..351aac6 100644
--- a/gevent/greenlet.py
+++ b/gevent/greenlet.py
@@ -156,6 +156,20 @@ class Greenlet(greenlet):
self._notifier = None
self._start_event = None
+ current = getcurrent()
+ self._leader = getattr(current, "_leader", None)
#! /usr/bin/env python
from gevent import tlmonkey, spawn, sleep, tpool
tlmonkey.patch_all()
def loop():
while 1:
print "hello"
sleep(5)
#! /usr/bin/env python
import gevent.monkey; gevent.monkey.patch_all()
import gevent, fcntl, os
def doit():
count = 0
while 1:
count += 1
diff --git a/apipkg.py b/apipkg.py
--- a/apipkg.py
+++ b/apipkg.py
@@ -30,7 +30,11 @@
def importobj(modpath, attrname):
module = __import__(modpath, None, None, ['__doc__'])
- return getattr(module, attrname)
+ attrs = attrname.split(".")
+ tmp = module
#! /usr/bin/env python
from gevent import monkey
# comment out the following line to make it work
monkey.patch_all()
import os, signal
from gevent import socket, core, event, Timeout, hub
pid2status = {}
def AliasModule(modname, modpath):
getmod = lambda: importobj(modpath, None) # do we need caching??
class AliasModule(ModuleType):
def __repr__(self):
return '<AliasModule %r for %r>' % (modname, modpath)
def __getattribute__(self, name):
return getattr(getmod(), name)