diff options
author | Tom Prince <tom.prince@ualberta.net> | 2012-01-28 14:43:04 -0500 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-01-28 21:22:39 +0000 |
commit | 5d0b77b26460e914a5e9990eab50b3638c369d6e (patch) | |
tree | 3280e1a1094c8390180d2e282b5cded2b7762c75 /alot | |
parent | 0de42edbed08c04fae0be3c591198d71ff1a84e3 (diff) |
Remove direct use of threading.
twisted includes tools for handling threaded code nicely. Use it.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/commands/envelope.py | 12 | ||||
-rw-r--r-- | alot/commands/globals.py | 15 |
2 files changed, 12 insertions, 15 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 2d209d19..af26b1ed 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -5,7 +5,7 @@ import logging import email import tempfile from twisted.internet.defer import inlineCallbacks -import threading +from twisted.internet import threads import datetime from alot.account import SendingMailFailed @@ -136,19 +136,17 @@ class SendCommand(Command): ui.notify('failed to send: %s' % returnvalue, priority='error') - write_fd = ui.mainloop.watch_pipe(afterwards) - def thread_code(): mail = envelope.construct_mail() try: account.send_mail(mail) except SendingMailFailed as e: - os.write(write_fd, unicode(e)) + return unicode(e) else: - os.write(write_fd, 'success') + return 'success' - thread = threading.Thread(target=thread_code) - thread.start() + d = threads.deferToThread(thread_code) + d.addCallback(afterwards) @registerCommand(MODE, 'edit') diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 28903894..ed5a63d5 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -1,6 +1,6 @@ import os import code -import threading +from twisted.internet import threads import subprocess import shlex import email @@ -166,8 +166,6 @@ class ExternalCommand(Command): logging.info('refocussing') ui.buffer_focus(callerbuffer) - write_fd = ui.mainloop.watch_pipe(afterwards) - def thread_code(*args): if self.path: if '{}' in self.commandstring: @@ -187,16 +185,17 @@ class ExternalCommand(Command): logging.info('calling external command: %s' % cmd) try: if 0 == subprocess.call(shlex.split(cmd)): - os.write(write_fd, 'success') + return 'success' except OSError, e: - os.write(write_fd, str(e)) + return str(e) if self.in_thread: - thread = threading.Thread(target=thread_code) - thread.start() + d = threads.deferToThread(thread_code) + d.addCallback(afterwards) else: ui.mainloop.screen.stop() - thread_code() + ret = thread_code() + afterwards(ret) ui.mainloop.screen.start() |