mirror of
https://github.com/ansible/awx.git
synced 2026-08-04 12:00:03 -02:30
Use closing consistently.
This commit is contained in:
@@ -9,6 +9,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
from contextlib import closing
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from multiprocessing import Process, Queue
|
from multiprocessing import Process, Queue
|
||||||
|
|
||||||
@@ -90,12 +91,12 @@ class CallbackReceiver(object):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def callback_handler(self, use_workers, worker_queues):
|
def callback_handler(self, use_workers, worker_queues):
|
||||||
pubsub = PubSub('callbacks')
|
|
||||||
message_number = 0
|
message_number = 0
|
||||||
total_messages = 0
|
total_messages = 0
|
||||||
last_parent_events = {}
|
last_parent_events = {}
|
||||||
|
|
||||||
for message in pubsub.subscribe():
|
with closing(PubSub('callbacks')) as callbacks:
|
||||||
|
for message in callbacks.subscribe(wait=0.1):
|
||||||
total_messages += 1
|
total_messages += 1
|
||||||
if not use_workers:
|
if not use_workers:
|
||||||
self.process_job_event(message)
|
self.process_job_event(message)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class PubSub(object):
|
|||||||
Ideally this should be used with `contextmanager.closing` to ensure
|
Ideally this should be used with `contextmanager.closing` to ensure
|
||||||
well-behavedness:
|
well-behavedness:
|
||||||
|
|
||||||
from contextmanager import closing
|
from contextlib import closing
|
||||||
|
|
||||||
with closing(PubSub('foobar')) as foobar:
|
with closing(PubSub('foobar')) as foobar:
|
||||||
for message in foobar.subscribe(wait=0.1):
|
for message in foobar.subscribe(wait=0.1):
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import sys
|
|||||||
import urllib
|
import urllib
|
||||||
import urlparse
|
import urlparse
|
||||||
import time
|
import time
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
# Requests
|
# Requests
|
||||||
import requests
|
import requests
|
||||||
@@ -125,8 +126,8 @@ class CallbackModule(object):
|
|||||||
self.connection_pid = active_pid
|
self.connection_pid = active_pid
|
||||||
|
|
||||||
# Publish the callback through Redis.
|
# Publish the callback through Redis.
|
||||||
pubsub = PubSub('callbacks')
|
with closing(PubSub('callbacks')) as callbacks:
|
||||||
pubsub.publish(msg)
|
callbacks.publish(msg)
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.info('Publish Exception: %r, retry=%d', e,
|
self.logger.info('Publish Exception: %r, retry=%d', e,
|
||||||
|
|||||||
Reference in New Issue
Block a user