Skip to content

Instantly share code, notes, and snippets.

@plq
Created December 28, 2013 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/8164989 to your computer and use it in GitHub Desktop.
Save plq/8164989 to your computer and use it in GitHub Desktop.
lxml segfault
from __future__ import print_function
from lxml import etree
from StringIO import StringIO
def coroutine(func):
def start(*args, **kwargs):
ret = func(*args, **kwargs)
try:
next(ret)
except StopIteration:
return None
return ret
return start
@coroutine
def yo_gen2(parent):
with parent.element("yo"):
while True:
a = yield
print(2, a)
@coroutine
def yo_gen(parent):
with etree.xmlfile(parent) as xf:
ret = yo_gen2(xf)
while True:
val = yield
ret.send(val)
gen = yo_gen(StringIO())
gen.send("hellooo")
try:
gen.throw(Exception())
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment