Gateway Timer script starts multiple threads despite the "Shared" tick being set

Hello.
Having an issue with Gateway Event timer scripts, manifested in that when the script is configured like so:
image
everytime the project being saved, the Gateway starts parallel thread and runs this script one more time in parallel to first one. The threads end only when their scripts finish working or the Gateway reboots.
The documentation on Gateway Event Scripts says:


So we have set all our scripts to Shared thread, but still as anyone saves the project we get another one thread.

Problem is that the script’s execution time varies widely from 60 sec to about 15000 sec (more than 4 hours) depending on many conditions.

The script is intended to collect data from one, but very slow OPC UA device so the program on the other side starts to receive multiple requests from many identical srcipts, which is not normal and causes failures and data errors.

Is there any way to make only one thread of script running at a time to avoid problems in data acquisition? Maybe make Gateway scripts restart on saving project, but I can’t figure out how to do that yet.

What additional data should I provide to solve the problem?
Thank You in advance.
Any related examples would be very appreciated.

And one more problem encountered (think it’s related to this post): Gateway Scripts diagnostics window doesn’t work for some reason with this script running:


With the script turned off Gateway Srcipt window opens normally.

Having Ignition version:
image

Script code’s part is listed below:


import time
from time import sleep

deviceName = "RM_NIKserver_ModbusGateway0"

try:
	ErrorsThisSession = 0
	print system.tag.write("[default]PowerMeters/scriptErrorsThisSession", 0)	#обнуляем счетчик ошибок в данном цикле
	ErrorsTotal = system.tag.read("[default]PowerMeters/scriptErrorsTotal").getValue() #считываем счетчик ошибок всего
except:
	print "Cannot write [default]PowerMeters/scriptErrorsThisSession"

try:
	a = system.tag.read("[default]PowerMeters/scriptCycleNumber")	#увеличиваем счетчик циклов опроса
	a.value = a.value + 1
	print system.tag.write("[default]PowerMeters/scriptCycleNumber", a)
except:
	result = 0
	print "Could not read cycle number"

startTime = system.date.now()
tp = "[default]PowerMeters/scriptLastStarted.value"			#запоминаем время начала скрипта
try:
#	result = system.tag.write(tp, startTime)
	print system.tag.write(tp, startTime)
except:
#	result = 0
	print "could not write [default]PowerMeters/scriptLastStarted.value"

print '>>> Script start at ', startTime

query = "SELECT * FROM RiverMall.counterlist where CounterResource='Electricity' and CounterManuf='NIK' ORDER BY SlaveID ASC"
data = system.db.runQuery(query)
print data, system.tag.write("[default]PowerMeters/scriptCountersTotal", data.getRowCount())		#записываем кол-во счетчиков всего

query = "SELECT * FROM RiverMall.counterlist where CounterResource='Electricity' and CounterStatus = 'connected' and CounterManuf='NIK' ORDER BY SlaveID ASC"
data = system.db.runQuery(query)																	#form a list of physical devices for data acquisition from DB
print data, system.tag.write("[default]PowerMeters/scriptCountersToRead", data.getRowCount())		#записываем кол-во счетчиков к вычитке
counter = 0

for counter in range(data.getRowCount()):

#-------------			10 попыток дисконнекта, не всегда срабатывает
	print "discon...>",
	for i in range(10):
		try:
			print str(i),
			system.device.setDeviceEnabled(deviceName, 0)
			sleep(3)
			print "Ok >",
			break
		except:
			print "failed disconnect >"
			break
		retryCount = 0
		while 1:
			print '.',
			a = system.tag.read("[default]PowerMeters/Connection State")
			print '.',
			quality = a.getQuality()
			print '.',
			if not quality.isGood():
				print quality, "+"
				break
			retryCount = retryCount + 1
			if retryCount==100:
				print "Could not disconnect."
				break
#-------------

	CounterName = data.getValueAt(counter,"CounterName")
	server = "OPC UA"
	slaveID = data.getValueAt(counter,"SlaveID")
	slaveName = data.getValueAt(counter,"CounterName")
	print str(deviceName) +" "+ str(slaveID)
	
	if slaveID != None:																					#формируем массив адресов тего для вычитки OPC
		path_SerialNo = "[" + str(deviceName) + "]" + str(slaveID) + ".IRS48:8"
#--------------------------------------------
#
#
#forming an array of parameters to request from modbusTCP-gate
#
#
#--------------------------------------------
##		path_fullPower_3phase = "[" + str(deviceName) + "]" + str(slaveID) + ".IRF300"

		paths = [path_SerialNo,
#--------------------------------------------
#
#
#forming an array of parameters to request from modbusTCP-gate
#
#
#--------------------------------------------
				]
		
		CounterTagFolderPath = data.getValueAt(counter,"CounterTagFolderPath")
		
		tagPath_SerialNo = CounterTagFolderPath + "/serialNo"			#формируем массив путей и имён тегов для записи значений
#--------------------------------------------
#
#
#forming an array of tag names to parse the request results into
#
#
#--------------------------------------------
		tagPath_communicationStatus = CounterTagFolderPath + "/communicationStatus"
		
		tagPaths = [tagPath_SerialNo,
#--------------------------------------------
#
#
#forming an array of tag names to parse the request results into
#
#
#--------------------------------------------
					]

		value = 1
		result = system.tag.write("[default]PowerMeters/scriptTagsTotal", len(paths)),	#записываем количество считываемых в этом цикле тегов

#-------------			10 попыток коннекта, не всегда срабатывает
		print "conn...",
		for i in range(10):
			try:
				print str(i),
				a = system.device.setDeviceEnabled(deviceName, 1)
				sleep(3)
				print "Ok >",
				break
			except:
				result = 0
				print "failed to connect >"

		retryCount = 0
		while 1:
			print '.',
			a = system.tag.read("[default]PowerMeters/Connection State")
			print '.',
			quality = a.getQuality()
			print '.',
			if quality.isGood():
				print quality, "+"
				break
			retryCount = retryCount + 1
			if retryCount==1000:
				print "no connection."
				break
#-------------

		values = []

		try:
			print "devID: ", str(counter-1)
			print "Name: ", slaveName
			print "Tags: ", len(paths)
			for i in range(len(paths)):
				a = system.tag.write("[default]PowerMeters/scriptCurrentDevice", "Id:" + str(slaveID) + " - " + slaveName),	#записываем название счетчика, который вычитывается сейчас
				a = system.tag.write("[default]PowerMeters/scriptTagCurrent", i),	#записываем номер тега, который вычитывается сейчас
				print str(i), str(system.date.now()), server, ":", paths[i], '==',
				try:
					value = system.opc.readValue(server, paths[i])
				except:
					print "cannot read parameter."
					ErrorsThisSession = ErrorsThisSession + 1
					ErrorsTotal = ErrorsTotal + 1
					value = qualifiedValue(-1, 'bad')
					a = system.tag.write("[default]PowerMeters/scriptErrorsThisSession", ErrorsThisSession)	#обновляем счетчик ошибок в данном цикле
					a = system.tag.write("[default]PowerMeters/scriptErrorsTotal", ErrorsTotal)	#обновляем счетчик ошибок всего
					continue
				if paths[i] == path_Aplus_Actual_T0:
					if value.getQuality().toString() == 'Bad':		#Если тег не считался, пишем CommunicationStatus = 2
						query = "UPDATE `RiverMall`.`counterlist` SET `CommunicationStatus` = '2' WHERE `CounterName` = \'" + CounterName + "\'"
						a=system.db.runQuery(query)
						a=system.tag.write(tagPath_communicationStatus,  2)
					else:											#Если тег считался, пишем CommunicationStatus = 1
						query = "UPDATE `RiverMall`.`counterlist` SET `CommunicationStatus` = '1' WHERE `CounterName` = \'" + CounterName + "\'"
						a=system.db.runQuery(query)
						a=system.tag.write(tagPath_communicationStatus,  1)
						value = (float(value.getValue() / float(1000)))									#для актива+ масштабируем 1:1000

				if paths[i] == path_Rminus_Actual_T0 or paths[i] == path_Rplus_Actual_T0:	#для реактива+ и - масштабируем 1:1000
					value = (float(value.getValue() / float(1000)))

				print value
				if (i % 15 == 0):															# need to reconnect after each 16 tags been read
#----------------																disconnect
					print "discon...>",
					for i in range(10):
						try:
							print str(i),
							system.device.setDeviceEnabled(deviceName, 0)
							sleep(3)
							print "Ok >",
							break
						except:
							print "failed to disconnect >"
							break
							retryCount = 0
							while 1:
								print '.',
								a = system.tag.read("[default]PowerMeters/Connection State")
								print '.',
								quality = a.getQuality()
								print '.',
								if not quality.isGood():
									print quality, "+"
									break
								retryCount = retryCount + 1
								if retryCount==100:
									print "Could not disconnect."
									break
#----------------																reconnect
					print "conn...",
					for i in range(10):
						try:
							print str(i),
							a = system.device.setDeviceEnabled(deviceName, 1)
							sleep(3)
							print "Ok >",
							break
						except:
							result = 0
							print "failed to connect >"


					retryCount = 0
					while 1:
						print '.',
						a = system.tag.read("[default]PowerMeters/Connection State")
						print '.',
						quality = a.getQuality()
						print '.',
						if quality.isGood():
							print quality, "+"
							break
						retryCount = retryCount + 1
						if retryCount==1000:
							print "no connection."
							break
				values.append(value)

#----------------
			print "==============================================================="
			print str(counter-1), ':', values
			print "==============================================================="
			try:
				print "Writing to tags...",
				tagsWritten = system.tag.writeBlocking(tagPaths, values)
				tagSuccessWritten = system.tag.write("[default]PowerMeters/LastSuccessDevice", counter)
				print tagsWritten, tagSuccessWritten, "ok"
			except:
				print "Unable to write tags devID:", str(counter-1)
				continue
		except:
			print 'error in cycle:', counter
			continue

#            system.device.setDeviceEnabled(deviceName, 0)
#            print "discon..."
			sleep(3)


endTime = system.date.now()
duration = system.date.secondsBetween(startTime, endTime)		#вычисляем длительность последнего исполнения скрипта

print '****************************************************************'
print '*** Script started at  ', startTime
print '*** Script end at      ', endTime
print '*** Script duration    ', duration, 'seconds.'
print '****************************************************************'

tp = "[default]PowerMeters/scriptLastDuration.value"			#запоминаем длительность последнего исполнения скрипта
try:
	result = system.tag.write(tp, duration)
except:
	print "could not write [default]PowerMeters/scriptLastDuration"

(Third-party program’s logs listed below)
As we can see from the log, devices number alternate constantly due to multiple requests.
This is bad, because may result in data errors.

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:37.714 [ dbg] Incoming request: 000100000006890401220002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:37.714 [ dbg] /dev 137, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 137
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:37.714 [ dbg] /dev 137, reg 290/ Instant electricity metrics, parameter 290:, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:37.714 [ dbg] /dev 137, reg 291/ Instant electricity metrics, parameter 291:, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:37.714 [ dbg] /dev 137, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 137: registry request #11649
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:37.715 [ dbg] askue: /dbg/ [137] SelectDevice(tcp:10.1.123.28:4196:nik_fw10_electricity_meter:676.15841:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:37.716 [ dbg] askue: Reading Instant electricity metrics..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:37.718 [ dbg] askue: Operation in progress: Opening socket, 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:43.623 [ dbg] askue: /dbg/ [137] async request done, error = 0, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:43.624 [ dbg] askue: Received value 28 (0,1), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:43.624 [ dbg] askue: Received value 7 (0,2), 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:34:43.625 [ dbg] askue: finished with tcp:10.1.123.28:4196:nik_fw10_electricity_meter:676.15841:3333333333333333:2 is_ok=1
[0x7fb978001360] [140434290505472  DeviceRegistry] 25.01.20 14:34:43.626 [ dbg] /dev 137, reg 290/ response value: registry 290, value 0.000000
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:34:43.626 [ dbg] /dev 137, reg 290/ RESPONSE: 00010000000b8904080000000000000000, DATA: 0000000000000000

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.376 [ dbg] Incoming request: 000800000006550401260002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.376 [ dbg] /dev 85, reg 294/ Incoming request: func: 4, register 294, register nr: 2, device id: 85
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.376 [ dbg] /dev 85, reg 294/ Instant electricity metrics, parameter 294:, 2 words

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.377 [ dbg] /dev 85, reg 294/ Sending response for request on register 294, 2 words...
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.377 [ dbg] /dev 85, reg 294/ RESPONSE: 00080000000b5504084492ca934492ca93, DATA: 4492ca934492ca93

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:11.409 [ dbg] /dev 85, reg 306/ RESPONSE: 000d0000000b55040843c4967843c49678, DATA: 43c4967843c49678
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:37.041 [ dbg] Incoming request: 0001000000067f0410000002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:35:37.041 [ dbg] /dev 127, reg 4096/ Incoming request: func: 4, register 4096, register nr: 2, device id: 127

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:35:37.049 [ dbg] askue: /dbg/ [127] SelectDevice(tcp:10.1.123.53:4196:nik_fw10_electricity_meter:649.3325:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:35:37.050 [ dbg] askue: Reading Cumulative current energy..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:35:38.300 [ dbg] askue: finished with tcp:10.1.123.53:4196:nik_fw10_electricity_meter:649.3325:3333333333333333:2 is_ok=1
[0x7fb978001360] [140434290505472  DeviceRegistry] 25.01.20 14:35:38.300 [ dbg] /dev 127, reg 4096/ response value: index 0, channel 0, tariff 0, value: 10427420.000000

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:00.323 [ dbg] Updating meters list...
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:00.324 [ dbg] askue: /dbg/ [0] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:00.324 [ dbg] askue: Reading meters list..., 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:00.348 [ dbg] Updated meters list, 182 records

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:36:09.007 [ dbg] Incoming request: 0001000000068c0410000002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:36:09.007 [ dbg] /dev 140, reg 4096/ Incoming request: func: 4, register 4096, register nr: 2, device id: 140
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:09.009 [ dbg] askue: Reading Cumulative current energy..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:36:10.298 [ dbg] askue: finished with tcp:10.1.122.48:4196:nik_fw10_electricity_meter:676.15376:3333333333333333:2 is_ok=1
[0x7fb978001360] [140434290505472  DeviceRegistry] 25.01.20 14:36:10.298 [ dbg] /dev 140, reg 4096/ response value: index 0, channel 0, tariff 0, value: 4475211.000000
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:37:22.198 [ dbg] Incoming request: 000100000006200401220002
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:37:22.198 [ dbg] /dev 32, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 32
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:37:22.198 [ dbg] askue: /dbg/ [32] SelectDevice(tcp:10.1.123.28:4196:nik_fw10_electricity_meter:649.3296:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:37:22.199 [ dbg] askue: Reading Instant electricity metrics..., 0

[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:37:28.243 [ dbg] /dev 32, reg 306/ Sending response for request on register 306, 2 words...
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:37:28.243 [ dbg] /dev 32, reg 306/ RESPONSE: 00070000000b20040844c2db1044c2db10, DATA: 44c2db1044c2db10
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:14.227 [ dbg] Incoming request: 0001000000068d0400300004
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:14.227 [ dbg] /dev 141, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 141
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:14.227 [ dbg] /dev 141, reg 48/ Serial number, 2 words
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:14.227 [ dbg] /dev 141, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 141: registry request #11671

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:22.251 [ dbg] askue: Operation in progress: Establishing connection, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:22.251 [ dbg] askue: /dbg/ [141] GetAsyncOperationStatus(30000), 0
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:29.248 [ dbg] Incoming request: 000200000006330400300004
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:29.248 [ dbg] /dev 51, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 51
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:29.248 [ dbg] /dev 51, reg 48/ Serial number, 2 words
[0x7fb978001360] [140434656990976 Thread (pooled)] 25.01.20 14:38:29.248 [ dbg] /dev 51, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 51: registry request #11672
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:30.252 [ dbg] askue: /dbg/ [141] event: 25.01.2020 14:38:30.251149	i	tcp	connecting_socket, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:30.252 [ dbg] askue: /dbg/ [141] status: 2, 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.260 [ dbg] askue: /dbg/ [141] error: askue::tcp::operation_timed_out, Operation canceled, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.260 [ dbg] askue: Operation timed out, 100
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.260 [ dbg] askue: finished with tcp:10.1.122.63:4196:nik_fw10_electricity_meter:650.8685:3333333333333333:2 is_ok=0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.261 [ dbg] askue: Connecting to server..., 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.261 [ dbg] askue: /dbg/ [51] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.269 [ dbg] askue: Reading Serial number..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.569 [ dbg] askue: /dbg/ [51] async request done, error = 0, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:38:38.569 [ dbg] askue: finished with tcp:10.1.123.67:4196:nik_fw10_electricity_meter:636.11794:3333333333333333:2 is_ok=1
[0x7fb978001360] [140434290505472  DeviceRegistry] 25.01.20 14:38:38.569 [ dbg] /dev 51, reg 48/ response value: 10432018

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:00.351 [ dbg] Updating meters list...
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:00.352 [ dbg] askue: /dbg/ [0] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:00.361 [ dbg] askue: Reading meters list..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:00.377 [ dbg] askue: finished with  is_ok=1
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:00.377 [ dbg] Updated meters list, 182 records
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:01.488 [ dbg] Incoming request: 0001000000062f0410000002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:01.488 [ dbg] /dev 47, reg 4096/ Incoming request: func: 4, register 4096, register nr: 2, device id: 47
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:01.490 [ dbg] askue: Reading Cumulative current energy..., 0

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:02.748 [ dbg] /dev 47, reg 4096/ RESPONSE: 00010000000b2f0408df1c7100df1c7100, DATA: df1c7100df1c7100
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:02.756 [ dbg] Incoming request: 0002000000066a0401220002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:02.756 [ dbg] /dev 106, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 106
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:02.756 [ dbg] askue: /dbg/ [106] SelectDevice(tcp:10.1.122.28:4196:nik_fw10_electricity_meter:650.7397:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:02.757 [ dbg] askue: Reading Instant electricity metrics..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:10.773 [ dbg] askue: /dbg/ [106] GetAsyncOperationStatus(30000), 0
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:17.766 [ dbg] Incoming request: 0003000000063f0401220002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:17.766 [ dbg] /dev 63, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 63
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:17.766 [ dbg] /dev 63, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 63: registry request #11675
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:18.774 [ dbg] askue: /dbg/ [106] event: 25.01.2020 14:46:18.773476	e	tcp	operation_timed_out, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:18.774 [ dbg] askue: /dbg/ [106] status: 2, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:18.774 [ dbg] askue: Operation in progress: Operation timed out, 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:26.792 [ dbg] askue: Connecting to server..., 0
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:26.792 [ dbg] /dev 106, reg 290/ Sending response for request on register 290, 2 words...
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:26.792 [ dbg] /dev 106, reg 290/ Error: 4 unknown_error
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:26.792 [ dbg] /dev 106, reg 290/ Response: 0002000000046a840104
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:26.793 [ dbg] askue: /dbg/ [63] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:26.794 [ dbg] askue: /dbg/ [63] AsyncReadAllInstantElectricityMetricRecords(), 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:26.801 [ dbg] askue: Operation in progress: Establishing connection, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:26.801 [ dbg] askue: /dbg/ [63] GetAsyncOperationStatus(30000), 0
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:32.818 [ dbg] Incoming request: 0004000000060c0410000002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:46:32.818 [ dbg] /dev 12, reg 4096/ Incoming request: func: 4, register 4096, register nr: 2, device id: 12
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:34.802 [ dbg] askue: /dbg/ [63] event: 25.01.2020 14:46:34.801172	e	tcp	operation_timed_out, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:34.802 [ dbg] askue: Operation in progress: Operation timed out, 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:50.821 [ dbg] askue: /dbg/ [63] error: askue::tcp::operation_timed_out, Operation canceled, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:50.821 [ dbg] askue: Operation timed out, 100
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:50.821 [ dbg] askue: Connecting to server..., 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:50.822 [ dbg] askue: /dbg/ [12] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:46:50.832 [ dbg] askue: /dbg/ [12] AsyncReadAllCurrentCumulativeEnergyRecords(), 0

[0x7fb978001360] [140434290505472  DeviceRegistry] 25.01.20 14:46:52.070 [ dbg] /dev 12, reg 4096/ response value: index 0, channel 0, tariff 0, value: 11987218.000000
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:54:52.725 [ dbg] Incoming request: 0001000000067b0401220002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:54:52.725 [ dbg] /dev 123, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 123
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:54:52.725 [ dbg] /dev 123, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 123: registry request #11677

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:00.748 [ dbg] askue: /dbg/ [123] GetAsyncOperationStatus(30000), 0
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:01.949 [ dbg] Incoming request: 000100000006a10401220002
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:01.950 [ dbg] /dev 161, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 161
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:01.950 [ dbg] /dev 161, reg 290/ Incoming request: func: 4, register 290, register nr: 2, device id: 161: registry request #11678
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:08.767 [ dbg] askue: /dbg/ [123] event: 25.01.2020 14:55:08.755735	e	tcp	operation_timed_out, 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.785 [ dbg] askue: /dbg/ [123] error: askue::tcp::operation_timed_out, Operation canceled, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.785 [ dbg] askue: Operation timed out, 100
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.785 [ dbg] askue: finished with tcp:10.1.122.28:4196:nik_fw10_electricity_meter:613.10244:3333333333333333:2 is_ok=0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.785 [ dbg] askue: Connecting to server..., 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.786 [ dbg] askue: /dbg/ [161] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.787 [ dbg] askue: /dbg/ [161] SelectDevice(tcp:10.1.122.94:4196:nik_fw10_electricity_meter:553.11966:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:16.788 [ dbg] askue: Reading Instant electricity metrics..., 0

[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:24.856 [ dbg] askue: /dbg/ [161] GetAsyncOperationStatus(30000), 0
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] Incoming request: 000300000006170400300004
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 23
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 48/ Serial number, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 49/ Serial number, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 50/ Serial number, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 51/ Serial number, 2 words
[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:32.423 [ dbg] /dev 23, reg 48/ Incoming request: func: 4, register 48, register nr: 4, device id: 23: registry request #11680
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:32.853 [ dbg] askue: /dbg/ [161] event: 25.01.2020 14:55:32.841759	e	tcp	operation_timed_out, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:32.853 [ dbg] askue: /dbg/ [161] event: 25.01.2020 14:55:32.841913	i	tcp	connecting_socket, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:32.853 [ dbg] askue: /dbg/ [161] status: 2, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:32.853 [ dbg] askue: Operation in progress: Operation timed out, 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:32.853 [ dbg] askue: Operation in progress: Opening socket, 0

[0x7fb978001360] [140434273720064 Thread (pooled)] 25.01.20 14:55:40.882 [ dbg] /dev 161, reg 290/ Response: 000100000004a1840104
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:40.884 [ dbg] askue: /dbg/ [173] SelectServerDatabase(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:40.886 [ dbg] askue: /dbg/ [173] SelectDevice(tcp:10.1.124.55:4196:nik_fw10_electricity_meter:648.4438:3333333333333333:2), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:40.886 [ dbg] askue: Reading Cumulative current energy..., 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:40.886 [ dbg] askue: /dbg/ [173] AsyncReadAllCurrentCumulativeEnergyRecords(), 0
[0x7fb978001360] [140434648598272     DataManager] 25.01.20 14:55:40.887 [ dbg] askue: /dbg/ [173] GetAsyncOperationStatus(30000), 0


Can you add print statements for debugging that show it’s running concurrently? I can’t see any reason why this script would be running concurrently unless it’s defined in multiple projects or something.

Maybe a project save could result in one instance overlapping an old one that hasn’t finished running but was running at the time of the save, though.

Shared vs dedicated thread doesn’t matter - the important thing is that you’ve got it set for Fixed Delay.

Unfortunately, ‘prints’ don’t work in scripting, they work only in Script Console and I’ve added
many of them just to debug my script in Console.
But i’ve added a few diagnostic tags in the code:

a = system.tag.write("[default]PowerMeters/scriptCurrentDevice", "Id:" + str(slaveID) + " - " + slaveName)

or

a = system.tag.write("[default]PowerMeters/scriptTagCurrent", i),

or

tagSuccessWritten = system.tag.write("[default]PowerMeters/LastSuccessDevice", counter)

in which I clearly see that devices are alternated like many scripts make requests at the same time.
image
The script makes requests to devices one by one, and I expect the counters increase during execution, but the values alternate randomly.

The other thing is, there are 2 more guys who can edit their different scripts and save them.

The Console output of my script looks like that:

>>> Script start at  Fri Jan 24 21:48:41 EET 2020
<PyDataset rows:184 cols:29>
discon...> 0 failed disconnect >
RM_NIKserver_ModbusGateway 38
2 conn... 0 failed to connect >
1 Ok > . . . Good +

devID:  38
Name:  PM_ER5_2_2-43
Tags:  16
2 2 0 Fri Jan 24 21:49:49 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRUI4096 == [1590966528, Good, Fri Jan 24 21:49:52 EET 2020 (1579895392376)]
2 2 1 Fri Jan 24 21:49:50 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRI4126 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 2 Fri Jan 24 21:49:50 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRI4116 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 3 Fri Jan 24 21:49:50 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF262 == [3.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398290)]
2 2 4 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF264 == [3.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398327)]
2 2 5 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF266 == [1.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398350)]
2 2 6 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF256 == [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398371)]
2 2 7 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF258 == [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398411)]
2 2 8 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF260 == [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398446)]
2 2 9 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF286 == [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398463)]
2 2 10 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF288 == [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398482)]
2 2 11 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF290 == [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398509)]
2 2 12 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF294 == [393.17554, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398547)]
2 2 13 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF296 == [393.17554, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398566)]
2 2 14 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRF298 == [131.05852, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398585)]
2 2 15 Fri Jan 24 21:49:56 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]38.IRS48:8 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
===============================================================
. 38 : [[1590966528, Good, Fri Jan 24 21:49:52 EET 2020 (1579895392376)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [3.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398290)], [3.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398327)], [1.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398350)], [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398371)], [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398411)], [227.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398446)], [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398463)], [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398482)], [0.0, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398509)], [393.17554, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398547)], [393.17554, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398566)], [131.05852, Good, Fri Jan 24 21:49:58 EET 2020 (1579895398585)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]]
===============================================================
Writing to tags... [Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good] 2 ok
discon...> 0 Ok > RM_NIKserver_ModbusGateway 39
2 conn... 0 Ok > . . . Good +

devID:  39
Name:  PM_ER6_1_1-07
Tags:  16
2 2 0 Fri Jan 24 21:50:18 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRUI4096 == [3920100352, Good, Fri Jan 24 21:50:21 EET 2020 (1579895421519)]
2 2 1 Fri Jan 24 21:50:19 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRI4126 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 2 Fri Jan 24 21:50:19 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRI4116 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 3 Fri Jan 24 21:50:19 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF262 == [4.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427436)]
2 2 4 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF264 == [16.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427472)]
2 2 5 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF266 == [9.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427510)]
2 2 6 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF256 == [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427528)]
2 2 7 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF258 == [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427560)]
2 2 8 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF260 == [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427588)]
2 2 9 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF286 == [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427629)]
2 2 10 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF288 == [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427648)]
2 2 11 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF290 == [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427680)]
2 2 12 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF294 == [524.2341, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427706)]
2 2 13 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF296 == [2096.9363, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427729)]
2 2 14 Fri Jan 24 21:50:25 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRF298 == [1179.5266, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427759)]
2 2 15 Fri Jan 24 21:50:26 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]39.IRS48:8 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
===============================================================
. 39 : [[3920100352, Good, Fri Jan 24 21:50:21 EET 2020 (1579895421519)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [4.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427436)], [16.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427472)], [9.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427510)], [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427528)], [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427560)], [227.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427588)], [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427629)], [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427648)], [0.0, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427680)], [524.2341, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427706)], [2096.9363, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427729)], [1179.5266, Good, Fri Jan 24 21:50:27 EET 2020 (1579895427759)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]]
===============================================================
Writing to tags... [Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good] 2 ok
discon...> 0 Ok > RM_NIKserver_ModbusGateway 40
2 conn... 0 Ok > . . . Good +

devID:  40
Name:  PM_ER0_4_CP3-HWS
Tags:  16
2 2 0 Fri Jan 24 21:50:47 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRUI4096 == [2043984645, Good, Fri Jan 24 21:50:50 EET 2020 (1579895450777)]
2 2 1 Fri Jan 24 21:50:49 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRI4126 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 2 Fri Jan 24 21:50:49 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRI4116 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 3 Fri Jan 24 21:50:49 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF262 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456685)]
2 2 4 Fri Jan 24 21:50:54 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF264 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456716)]
2 2 5 Fri Jan 24 21:50:54 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF266 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456773)]
2 2 6 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF256 == [235.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456824)]
2 2 7 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF258 == [234.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456865)]
2 2 8 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF260 == [235.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456881)]
2 2 9 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF286 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456933)]
2 2 10 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF288 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456954)]
2 2 11 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF290 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456970)]
2 2 12 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF294 == [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456991)]
2 2 13 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF296 == [0.0, Good, Fri Jan 24 21:50:57 EET 2020 (1579895457013)]
2 2 14 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRF298 == [0.0, Good, Fri Jan 24 21:50:57 EET 2020 (1579895457037)]
2 2 15 Fri Jan 24 21:50:55 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]40.IRS48:8 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
===============================================================
. 40 : [[2043984645, Good, Fri Jan 24 21:50:50 EET 2020 (1579895450777)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456685)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456716)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456773)], [235.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456824)], [234.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456865)], [235.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456881)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456933)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456954)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456970)], [0.0, Good, Fri Jan 24 21:50:56 EET 2020 (1579895456991)], [0.0, Good, Fri Jan 24 21:50:57 EET 2020 (1579895457013)], [0.0, Good, Fri Jan 24 21:50:57 EET 2020 (1579895457037)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]]
===============================================================
Writing to tags... [Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good] 2 ok
discon...> 0 Ok > RM_NIKserver_ModbusGateway 41
2 conn... 0 Ok > . . . Good +

devID:  41
Name:  PM_ER1_2_2-20
Tags:  16
2 2 0 Fri Jan 24 21:51:16 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRUI4096 == [841871616, Good, Fri Jan 24 21:51:20 EET 2020 (1579895480023)]
2 2 1 Fri Jan 24 21:51:18 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRI4126 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 2 Fri Jan 24 21:51:18 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRI4116 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
2 2 3 Fri Jan 24 21:51:18 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF262 == [12.0, Good, Fri Jan 24 21:51:25 EET 2020 (1579895485955)]
2 2 4 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF264 == [14.0, Good, Fri Jan 24 21:51:25 EET 2020 (1579895485995)]
2 2 5 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF266 == [5.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486025)]
2 2 6 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF256 == [223.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486045)]
2 2 7 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF258 == [223.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486075)]
2 2 8 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF260 == [225.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486101)]
2 2 9 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF286 == [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486118)]
2 2 10 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF288 == [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486156)]
2 2 11 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF290 == [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486198)]
2 2 12 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF294 == [1544.9894, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486223)]
2 2 13 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF296 == [1802.4875, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486252)]
2 2 14 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRF298 == [649.51904, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486296)]
2 2 15 Fri Jan 24 21:51:24 EET 2020 OPC UA : [RM_NIKserver_ModbusGateway]41.IRS48:8 == [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]
===============================================================
. 41 : [[841871616, Good, Fri Jan 24 21:51:20 EET 2020 (1579895480023)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)], [12.0, Good, Fri Jan 24 21:51:25 EET 2020 (1579895485955)], [14.0, Good, Fri Jan 24 21:51:25 EET 2020 (1579895485995)], [5.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486025)], [223.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486045)], [223.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486075)], [225.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486101)], [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486118)], [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486156)], [0.0, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486198)], [1544.9894, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486223)], [1802.4875, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486252)], [649.51904, Good, Fri Jan 24 21:51:26 EET 2020 (1579895486296)], [null, Bad, Mon Jan 01 02:00:00 EET 1601 (-11644473600000)]]
===============================================================
Writing to tags... [Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good, Good] 2 ok
****************************************************************
*** Script started at   Fri Jan 24 21:48:41 EET 2020
*** Script end at       Fri Jan 24 21:51:39 EET 2020
*** Script duration     177 seconds.
****************************************************************
2
>>>

Since this script is running in gateway scope your print statements will go to the wrapper.log files wherever Ignition is installed.

I would suggest before any further troubleshooting you change all your instances of system.tag.write to system.tag.writeBlocking.

1 Like

This is most likely the correct answer.
Is there a way to drop the old script’s execution?
Maybe, it’s not the most right way, but it would be better than having many instances of script running.

Thanks a lot, I’ll try that out.

Maybe create a boolean tag that indicates the script is running. Set it true at the start of the script and then in finally clause set it back to false (so you run the script in a try block). Then the first thing the script does is check to see if it’s already running and if so just returns.

Kind of a hack, but might work…

1 Like

Thanks, that’s what I thought to do…)

It’s not bulletproof because there’s no atomic compare and swap operation for tags…

If you were truly unlucky 2 instances of the script started at the same time could simultaneously read it as false and start running. But I don’t think that’s very likely.

I recommend saving the thread name in the globals dictionary at the beginning of the background function. Then checking that it hasn’t changed regularly in the long-running script. If it has changed, abort immediately with a log entry reporting that it has been superseded. Even better for permanent threads of this kind, is to start it in the initialization of a code module, and have a regular timer function just call into that module to ensure it is loaded. The gateway event would just be a one-liner:

project.background.someDummyFunction()

Note that the event code doesn’t call in to do any work. The background thread does all of that, and should run forever, or until replaced.
The background script module would be something like this:

from java.lang import Thread

gwg = system.util.getGlobals()
myGlobalKey = "someName"

def task(myThreadName):
	while True:
		# Some repetitive task stuff.  If multiple different tasks, do the
		# following test often throughout the code.
		if gwg[myGlobalKey] != myThreadName:
			return

def restarter():
	myThreadName = str(Thread.currentThread())
	gwg[myGlobalKey] = myThreadName
	while True:
		try:
			task(myThreadName)
		except:
			# Restart on errors, but throttle for some milliseconds.
			# Probably ought to log something here.
			Thread.sleep(2000L)
			continue
		break

system.util.invokeAsynchronous(restarter)

def someDummyFunction():
	pass

Note the trick to restart the actual task() on errors but not on normal return.

1 Like