Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method should decorate by tornado.web.asynchronous ? #4

Open
jacklee2012 opened this issue Jul 23, 2012 · 0 comments
Open

method should decorate by tornado.web.asynchronous ? #4

jacklee2012 opened this issue Jul 23, 2012 · 0 comments
Assignees

Comments

@jacklee2012
Copy link

the project example code show blow:

def post(self):

        def _finish(num):
            print 'sended %d message(s)' % num
            self.render("index.html")

        message = EmailMessage(
            self.get_argument('subject'),
            self.get_argument('message'),
            '<your google mail>',
            [self.get_argument('email')],
            connection=self.mail_connection
        )
        message.send()#callback=_finish)
        self.render("index.html")

but if don't use tornado.web.asynchronous to decorate the post method, the socket will closed after the post method return
and cause:

Exception in callback <tornado.stack_context._StackContextWrapper object at 0x8cf2784>
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/ioloop.py", line 399, in _run_callback
        callback()
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/iostream.py", line 304, in wrapper
        callback(*args)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/stack_context.py", line 199, in wrapped
        callback(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 357, in inner
        self.set_result(key, result)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 291, in set_result
        self.run()
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 321, in run
        yielded = self.gen.send(next)
      File "/usr/local/lib/python2.7/dist-packages/tornadomail/smtplib.py", line 385, in docmd
        self.getreply(callback)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 107, in wrapper
        runner.run()
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 319, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/local/lib/python2.7/dist-packages/tornadomail/smtplib.py", line 356, in getreply
        line = yield gen.Task(self.sock.read_until, '\n')
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 341, in run
        self.yield_point.start(self)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/gen.py", line 223, in start
        self.func(*self.args, **self.kwargs)
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/iostream.py", line 160, in read_until
        self._check_closed()
      File "/usr/local/lib/python2.7/dist-packages/tornado-2.2-py2.7.egg/tornado/iostream.py", line 535, in _check_closed
        raise IOError("Stream is closed")
    IOError: Stream is closed
@ghost ghost assigned equeny Sep 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants