summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/commands/envelope.py12
-rw-r--r--alot/commands/globals.py15
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()