From db38caf5f401abc7d6570a372ae89e48cf16bd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verch=C3=A8re?= Date: Sat, 9 Sep 2017 23:11:03 +0200 Subject: [PATCH] Refs #15. Trying to understand twisted thread mechanism --- vmware_exporter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vmware_exporter.py b/vmware_exporter.py index 53de39d..dd6460b 100755 --- a/vmware_exporter.py +++ b/vmware_exporter.py @@ -18,8 +18,7 @@ # Twisted from twisted.web.server import Site, NOT_DONE_YET from twisted.web.resource import Resource -from twisted.internet import reactor -from twisted.internet.task import deferLater +from twisted.internet import reactor, threads # VMWare specific imports from pyVmomi import vim, vmodl @@ -53,8 +52,7 @@ def render_GET(self, request): if not request.args.get('target', [None])[0]: request.setResponseCode(404) return 'No target defined\r\n'.encode() - d = deferLater(reactor, 0, lambda: request) - d.addCallback(self.generate_latest_target) + d = threads.deferToThread(self.generate_latest_target, request) d.addErrback(self.errback, request) return NOT_DONE_YET else: