mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixes: #3232. Use of datetime consistent with module_utils/basic.py
This commit is contained in:
parent
02abe0b7c9
commit
7b93cd7db2
1 changed files with 9 additions and 9 deletions
|
@ -98,7 +98,7 @@ import traceback
|
||||||
|
|
||||||
import SocketServer
|
import SocketServer
|
||||||
|
|
||||||
from datetime import datetime
|
import datetime
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
|
@ -257,7 +257,7 @@ class LocalSocketThread(Thread):
|
||||||
# shutdown sooner than expected for new cliets
|
# shutdown sooner than expected for new cliets
|
||||||
try:
|
try:
|
||||||
self.server.last_event_lock.acquire()
|
self.server.last_event_lock.acquire()
|
||||||
self.server.last_event = datetime.now()
|
self.server.last_event = datetime.datetime.now()
|
||||||
finally:
|
finally:
|
||||||
self.server.last_event_lock.release()
|
self.server.last_event_lock.release()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -293,7 +293,7 @@ class ThreadWithReturnValue(Thread):
|
||||||
|
|
||||||
class ThreadedTCPServer(SocketServer.ThreadingTCPServer):
|
class ThreadedTCPServer(SocketServer.ThreadingTCPServer):
|
||||||
key_list = []
|
key_list = []
|
||||||
last_event = datetime.now()
|
last_event = datetime.datetime.now()
|
||||||
last_event_lock = Lock()
|
last_event_lock = Lock()
|
||||||
def __init__(self, server_address, RequestHandlerClass, module, password, timeout, use_ipv6=False):
|
def __init__(self, server_address, RequestHandlerClass, module, password, timeout, use_ipv6=False):
|
||||||
self.module = module
|
self.module = module
|
||||||
|
@ -322,7 +322,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
||||||
def send_data(self, data):
|
def send_data(self, data):
|
||||||
try:
|
try:
|
||||||
self.server.last_event_lock.acquire()
|
self.server.last_event_lock.acquire()
|
||||||
self.server.last_event = datetime.now()
|
self.server.last_event = datetime.datetime.now()
|
||||||
finally:
|
finally:
|
||||||
self.server.last_event_lock.release()
|
self.server.last_event_lock.release()
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.server.last_event_lock.acquire()
|
self.server.last_event_lock.acquire()
|
||||||
self.server.last_event = datetime.now()
|
self.server.last_event = datetime.datetime.now()
|
||||||
finally:
|
finally:
|
||||||
self.server.last_event_lock.release()
|
self.server.last_event_lock.release()
|
||||||
|
|
||||||
|
@ -402,15 +402,15 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
|
||||||
|
|
||||||
mode = data['mode']
|
mode = data['mode']
|
||||||
response = {}
|
response = {}
|
||||||
last_pong = datetime.now()
|
last_pong = datetime.datetime.now()
|
||||||
if mode == 'command':
|
if mode == 'command':
|
||||||
vvvv("received a command request, running it")
|
vvvv("received a command request, running it")
|
||||||
twrv = ThreadWithReturnValue(target=self.command, args=(data,))
|
twrv = ThreadWithReturnValue(target=self.command, args=(data,))
|
||||||
twrv.start()
|
twrv.start()
|
||||||
response = None
|
response = None
|
||||||
while twrv.is_alive():
|
while twrv.is_alive():
|
||||||
if (datetime.now() - last_pong).seconds >= 15:
|
if (datetime.datetime.now() - last_pong).seconds >= 15:
|
||||||
last_pong = datetime.now()
|
last_pong = datetime.datetime.now()
|
||||||
vvvv("command still running, sending keepalive packet")
|
vvvv("command still running, sending keepalive packet")
|
||||||
data2 = json.dumps(dict(pong=True))
|
data2 = json.dumps(dict(pong=True))
|
||||||
data2 = self.active_key.Encrypt(data2)
|
data2 = self.active_key.Encrypt(data2)
|
||||||
|
@ -589,7 +589,7 @@ def daemonize(module, password, port, timeout, minutes, use_ipv6, pid_file):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
server.last_event_lock.acquire()
|
server.last_event_lock.acquire()
|
||||||
td = datetime.now() - server.last_event
|
td = datetime.datetime.now() - server.last_event
|
||||||
# older python timedelta objects don't have total_seconds(),
|
# older python timedelta objects don't have total_seconds(),
|
||||||
# so we use the formula from the docs to calculate it
|
# so we use the formula from the docs to calculate it
|
||||||
total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
|
total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
|
||||||
|
|
Loading…
Reference in a new issue