Closedown

This commit is contained in:
gac-x04sa
2019-02-26 15:36:00 +01:00
parent b73b7b5e50
commit 27b2a1601e
4 changed files with 28 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
#Tue Feb 26 15:15:47 CET 2019
#Tue Feb 26 15:33:43 CET 2019
count_time=1.0
geometry=fourcv
roi=190 45 290 125

View File

@@ -3,7 +3,6 @@ import numpy
def img_get_int(fname, thres1, thres2, thres3, thres4, header, width, height, depth, x1,y1,x2,y2, bx1,by1,bx2,by2 ):
# read actual image file
img = numpy.fromfile(fname, dtype=numpy.uint32)
print (str(len(img)) + " - " + str(height) + " x " + str( width))
img.shape = height, width
# signal roi
area_I = ( x2 - x1 + 1) * ( y2 - y1 + 1)

View File

@@ -53,73 +53,6 @@ class ImageMatrix(ReadonlyRegisterBase, ReadonlyRegisterMatrix, Readable.Integer
def is_locked(filepath):
"""Checks if a file is locked by opening it in append mode.
If no exception thrown, then the file is not locked.
"""
locked = None
file_object = None
filepath = os.path.abspath(filepath)
if os.path.exists(filepath):
try:
print "Trying to open %s." % filepath
buffer_size = 8
# Opening file in append mode and read the first 8 characters.
file_object = open(filepath, 'a', buffer_size)
if file_object:
print "%s is not locked." % filepath
locked = False
except IOError, message:
print "File is locked (unable to open in append mode). %s." % \
message
locked = True
finally:
if file_object:
file_object.close()
print "%s closed." % filepath
else:
print "%s not found." % filepath
return locked
def wait_for_files(filepaths, timeout = None):
"""Checks if the files are ready.
For a file to be ready it must exist and can be opened in append
mode.
"""
wait_time = 0.01
for filepath in filepaths:
filepath = os.path.abspath(filepath)
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath):
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)
# If the file exists but locked, wait wait_time seconds and check
# again until it's no longer locked by another process.
while is_locked(filepath):
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)
def wait_for_file_size(filepath, size, timeout = None):
"""Wait for a file to exist, and reach a given size.
"""
wait_time = 0.01
filepath = os.path.abspath(filepath)
start = time.time()
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath) or size > os.path.getsize(filepath):
if (timeout is not None) and (time.time() -start > timeout):
raise Exception(filepath + " hasn't arrived in time")
time.sleep(wait_time)
class Image(DeviceBase, Readable):
def __init__(self, name, pixel):
DeviceBase.__init__(self, name)
@@ -140,7 +73,7 @@ class Image(DeviceBase, Readable):
file_size = 4 * self.pixel.PIX_XDIM * self.pixel.PIX_YDIM
print "Waiting image file: " , filename, " size=", file_size
wait_for_file_size(filename, file_size)
wait_for_file_size(filename, file_size, 20.0)
threshold1 = self.pixel.threshold1
threshold2 = self.pixel.threshold2

View File

@@ -267,9 +267,10 @@ def append_diag_datasets(parent = None):
###################################################################################################
# Configuration
# Utilities
###################################################################################################
def is_locked(filepath):
"""Checks if a file is locked by opening it in append mode.
If no exception thrown, then the file is not locked.
@@ -279,10 +280,12 @@ def is_locked(filepath):
filepath = os.path.abspath(filepath)
if os.path.exists(filepath):
try:
print "Trying to open %s." % filepath
buffer_size = 8
# Opening file in append mode and read the first 8 characters.
file_object = open(filepath, 'a', buffer_size)
if file_object:
print "%s is not locked." % filepath
locked = False
except IOError, message:
print "File is locked (unable to open in append mode). %s." % \
@@ -291,11 +294,12 @@ def is_locked(filepath):
finally:
if file_object:
file_object.close()
print "%s closed." % filepath
else:
print "%s not found." % filepath
return locked
def wait_for_files(filepaths):
def wait_for_files(filepaths, timeout = None):
"""Checks if the files are ready.
For a file to be ready it must exist and can be opened in append
@@ -307,22 +311,40 @@ def wait_for_files(filepaths):
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath):
if (timeout is not None) and (time.time() -start > timeout):
err = filepath + " hasn't arrived in time"
print err
raise Exception(err)
time.sleep(wait_time)
# If the file exists but locked, wait wait_time seconds and check
# again until it's no longer locked by another process.
while is_locked(filepath):
if (timeout is not None) and (time.time() -start > timeout):
err = filepath + " hasn't unlock in time"
print err
raise Exception(err)
time.sleep(wait_time)
def wait_for_file_size(filepath, size):
def wait_for_file_size(filepath, size, timeout = None):
"""Wait for a file to exist, and reach a given size.
"""
wait_time = 0.01
filepath = os.path.abspath(filepath)
start = time.time()
# If the file doesn't exist, wait wait_time seconds and try again
# until it's found.
while not os.path.exists(filepath) and os.path.getsize(filepath) < size:
while not os.path.exists(filepath) or size > os.path.getsize(filepath):
if (timeout is not None) and (time.time() -start > timeout):
err = filepath + " hasn't arrived in time"
print err
raise Exception(err)
time.sleep(wait_time)
###################################################################################################
# Configuration
###################################################################################################