cjnfuncs 3.2__tar.gz → 3.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cjnfuncs-3.2/src/cjnfuncs.egg-info → cjnfuncs-3.2.1}/PKG-INFO +1 -1
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/pyproject.toml +8 -3
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/configman.py +1 -1
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/core.py +10 -2
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/resourcelock.py +29 -19
- {cjnfuncs-3.2 → cjnfuncs-3.2.1/src/cjnfuncs.egg-info}/PKG-INFO +1 -1
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/LICENSE +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/README.md +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/setup.cfg +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/SMTP.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/__init__.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/deployfiles.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/mungePath.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/rwt.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs/timevalue.py +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs.egg-info/SOURCES.txt +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs.egg-info/dependency_links.txt +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs.egg-info/entry_points.txt +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs.egg-info/requires.txt +0 -0
- {cjnfuncs-3.2 → cjnfuncs-3.2.1}/src/cjnfuncs.egg-info/top_level.txt +0 -0
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = 'cjnfuncs'
|
|
3
|
-
version = '3.2'
|
|
3
|
+
version = '3.2.1'
|
|
4
|
+
# 3.2.1 - Release
|
|
5
|
+
# resourcelock info level log on lock unget request ignored if lock not owned by current process and not forced
|
|
6
|
+
# resourcelock --verbose switch
|
|
7
|
+
# periodic_log returns True/False whether call was logged
|
|
8
|
+
# doc fixes
|
|
4
9
|
# 3.2 - Release - New features: persistent_config and shared memory block handling
|
|
5
10
|
# 3.1.1 - separate resourcelock_islocked logger, get_next_dt days/weeks offset
|
|
6
|
-
# 3.1 -
|
|
11
|
+
# 3.1 - Release
|
|
7
12
|
# Support for and use of child loggers
|
|
8
13
|
# deployfiles create empty dir
|
|
9
14
|
# Windows fixes
|
|
10
15
|
# config_item() safe_mode switch
|
|
11
16
|
# mungePath set_attributes from default False
|
|
12
17
|
# 3.0.1 - Allow '.' in config section names
|
|
13
|
-
# 3.0 -
|
|
18
|
+
# 3.0 - Release
|
|
14
19
|
# added get_next_dt
|
|
15
20
|
# reworked deployfiles and tests
|
|
16
21
|
# added rwt_debug
|
|
@@ -1305,7 +1305,7 @@ save after critical data has been written to the config.
|
|
|
1305
1305
|
### Args
|
|
1306
1306
|
`exit` (bool, default False)
|
|
1307
1307
|
- If True, informs the scheduled save thread to do a final save and then terminate
|
|
1308
|
-
- If False, the persistent_config data is directly written to the `config_file`
|
|
1308
|
+
- If False, or no scheduled save thread is running, the persistent_config data is directly written to the `config_file`
|
|
1309
1309
|
|
|
1310
1310
|
|
|
1311
1311
|
### Returns
|
|
@@ -460,6 +460,8 @@ class _periodic_log:
|
|
|
460
460
|
_logger = logging.getLogger(self.logger_name)
|
|
461
461
|
_logger.log(log_level, f"[PLog-{cat}] {message}")
|
|
462
462
|
self.next_dt = now_dt + self.log_interval
|
|
463
|
+
return True
|
|
464
|
+
return False
|
|
463
465
|
|
|
464
466
|
|
|
465
467
|
def periodic_log(message, category='Cat1', logger_name='', log_interval='10m', log_level=None):
|
|
@@ -494,7 +496,13 @@ for this category (ignored of subsequent calls).
|
|
|
494
496
|
|
|
495
497
|
|
|
496
498
|
### Returns
|
|
497
|
-
-
|
|
499
|
+
- True: This call was logged
|
|
500
|
+
- False: This call was skipped due to `log_interval` not being met
|
|
501
|
+
- Raises TypeError if input params are not valid
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
### Behaviors and rules
|
|
505
|
+
- A call to periodic_log() returns a boolean (True/False) which may be used to gate further operations, such as sending a notification.
|
|
498
506
|
"""
|
|
499
507
|
if category not in cats:
|
|
500
508
|
if log_level is None:
|
|
@@ -503,4 +511,4 @@ for this category (ignored of subsequent calls).
|
|
|
503
511
|
cats[category] = xx
|
|
504
512
|
|
|
505
513
|
p_logger = cats[category]
|
|
506
|
-
p_logger.plog(message, log_level, category)
|
|
514
|
+
return p_logger.plog(message, log_level, category)
|
|
@@ -6,7 +6,7 @@ Only works on Linux
|
|
|
6
6
|
|
|
7
7
|
#==========================================================
|
|
8
8
|
#
|
|
9
|
-
# Chris Nelson, Copyright 2024-
|
|
9
|
+
# Chris Nelson, Copyright 2024-2026
|
|
10
10
|
#
|
|
11
11
|
#==========================================================
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ import posix_ipc
|
|
|
16
16
|
import mmap
|
|
17
17
|
import os
|
|
18
18
|
import datetime
|
|
19
|
-
from .core import logging, set_toolname, setuplogging
|
|
19
|
+
from .core import logging, set_toolname, setuplogging, set_logging_level
|
|
20
20
|
|
|
21
21
|
import importlib.metadata
|
|
22
22
|
__version__ = importlib.metadata.version(__package__ or __name__)
|
|
@@ -76,8 +76,8 @@ Use the CLI command `resourcelock <lockname> unget` to manually release the lock
|
|
|
76
76
|
resource_lock() uses `posix_ipc.Semaphore`, which is a counter mechanism. `get_lock()`
|
|
77
77
|
decrements the counter to 0, indicating a locked state. `unget_lock()` increments the
|
|
78
78
|
counter (non-zero is unlocked). `unget_lock()` wont increment the counter unless the counter is
|
|
79
|
-
currently 0 (indicating locked), so it is ***recommended*** to
|
|
80
|
-
|
|
79
|
+
currently 0 (indicating locked), so it is ***recommended*** to place (possibly extraneous) `unget_lock()` calls
|
|
80
|
+
in your interrupt-trapped cleanup code so that interrupted code certainly releases the lock.
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
### Args
|
|
@@ -156,10 +156,10 @@ with timeout.
|
|
|
156
156
|
|
|
157
157
|
`lock_info` (str, default '')
|
|
158
158
|
- Optional debugging info string for indicating when and by whom the lock was set. Logged at the debug level.
|
|
159
|
-
- The datetime is prepended to lock_info.
|
|
159
|
+
- The current datetime is prepended to lock_info.
|
|
160
160
|
- A useful lock_info string format might be `<module_name>.<function_name> <get_lock_call_instance_number>`, eg,
|
|
161
161
|
`tempmon.measure_loop #3`.
|
|
162
|
-
- This string remains in place after an unget() call
|
|
162
|
+
- This string remains in place after an unget() call for lock history purposes while debugging.
|
|
163
163
|
|
|
164
164
|
### Returns
|
|
165
165
|
- True: Lock successfully acquired, timeout time not exceeded
|
|
@@ -197,7 +197,7 @@ If the lock was acquired by the current process then release the lock.
|
|
|
197
197
|
- If the lock is not currently set then the `unget_lock()` call is discarded, leaving the lock
|
|
198
198
|
in the same unset state.
|
|
199
199
|
- If the lock is currently set but _not_ acquired by this process then don't release the lock,
|
|
200
|
-
unless `force=True`.
|
|
200
|
+
unless `force=True`. _Lock unget request ignored_ calls are logged at the info level.
|
|
201
201
|
|
|
202
202
|
### Arg
|
|
203
203
|
`force` (bool, default False)
|
|
@@ -207,7 +207,7 @@ unless `force=True`.
|
|
|
207
207
|
|
|
208
208
|
`where_called` (str, default '')
|
|
209
209
|
- Debugging aid string for indicating what code released the lock. Logged at the debug level.
|
|
210
|
-
Not stored
|
|
210
|
+
Not stored nor available to a later call.
|
|
211
211
|
|
|
212
212
|
### Returns
|
|
213
213
|
- True: Lock successfully released
|
|
@@ -225,7 +225,7 @@ Not stored anywhere, nor available to a later call.
|
|
|
225
225
|
resourcelock_logger.debug (f"<{self.lockname[1:]}> lock force released <{where_called}>")
|
|
226
226
|
return True
|
|
227
227
|
else:
|
|
228
|
-
resourcelock_logger.
|
|
228
|
+
resourcelock_logger.info (f"<{self.lockname[1:]}> lock unget request ignored - lock not owned by current process <{where_called}>")
|
|
229
229
|
return False
|
|
230
230
|
else:
|
|
231
231
|
resourcelock_logger.debug (f"<{self.lockname[1:]}> Extraneous lock unget request ignored <{where_called}>")
|
|
@@ -244,6 +244,9 @@ Not stored anywhere, nor available to a later call.
|
|
|
244
244
|
|
|
245
245
|
***resource_lock() class member function***
|
|
246
246
|
|
|
247
|
+
Note that `is_locked()` uses a separate child logger - `'cjnfuncs.resourcelock_islocked'` - so that `is_locked()` may be
|
|
248
|
+
checked in a loop without flooding the log. `is_locked()` calls are logged at the debug level.
|
|
249
|
+
|
|
247
250
|
### Returns
|
|
248
251
|
- True if currently locked, else False
|
|
249
252
|
"""
|
|
@@ -387,8 +390,6 @@ Commands:
|
|
|
387
390
|
|
|
388
391
|
set_toolname (TOOLNAME)
|
|
389
392
|
setuplogging()
|
|
390
|
-
logging.getLogger('cjnfuncs.resourcelock').setLevel(logging.DEBUG)
|
|
391
|
-
logging.getLogger('cjnfuncs.resourcelock_islocked').setLevel(logging.DEBUG)
|
|
392
393
|
|
|
393
394
|
GET_TIMEOUT = 0.5
|
|
394
395
|
TRACE_INTERVAL = 0.5
|
|
@@ -407,30 +408,39 @@ Commands:
|
|
|
407
408
|
help="After a successful get, unget the lock in (float) sec")
|
|
408
409
|
parser.add_argument('-u', '--update', type=float, default=TRACE_INTERVAL,
|
|
409
410
|
help=f"Trace update interval (default {TRACE_INTERVAL} sec)")
|
|
411
|
+
parser.add_argument('-v', '--verbose', action='count', default=0,
|
|
412
|
+
help="Print status and activity messages (-vv for debug level logging)")
|
|
410
413
|
parser.add_argument('-V', '--version', action='version', version=f"{TOOLNAME} {__version__}",
|
|
411
414
|
help="Print version number and exit")
|
|
412
415
|
args = parser.parse_args()
|
|
413
416
|
|
|
414
417
|
|
|
418
|
+
ll = [logging.WARNING, logging.INFO, logging.DEBUG][args.verbose]
|
|
419
|
+
set_logging_level (ll, logger_name='cjnfuncs.resourcelock')
|
|
420
|
+
set_logging_level (ll, logger_name='cjnfuncs.resourcelock_islocked')
|
|
421
|
+
|
|
415
422
|
lock = resource_lock(args.LockName)
|
|
416
423
|
|
|
417
424
|
if args.Command == "get":
|
|
418
425
|
_timeout = args.get_timeout
|
|
419
426
|
if _timeout == -1:
|
|
420
427
|
_timeout = None
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
428
|
+
get_result = lock.get_lock(timeout=_timeout, lock_info=args.message)
|
|
429
|
+
print (f"<{args.LockName}> get_lock called - Returned <{get_result}>, Currently locked: <{lock.is_locked()}>, Lock info: <{lock.get_lock_info()}>")
|
|
430
|
+
if get_result and args.auto_unget:
|
|
431
|
+
print (f"Release lock after <{args.auto_unget}> sec delay")
|
|
432
|
+
sleep(args.auto_unget)
|
|
433
|
+
unget_result = lock.unget_lock(where_called=f'{args.message} - auto unget')
|
|
434
|
+
print (f"<{args.LockName}> unget_lock called - Returned <{unget_result}>, Currently locked: <{lock.is_locked()}>, Lock info: <{lock.get_lock_info()}>")
|
|
426
435
|
|
|
427
436
|
elif args.Command == "unget":
|
|
428
|
-
lock.unget_lock(force=True, where_called=args.message)
|
|
437
|
+
unget_result = lock.unget_lock(force=True, where_called=args.message)
|
|
438
|
+
print (f"<{args.LockName}> unget_lock called - Returned <{unget_result}>, Currently locked: <{lock.is_locked()}>, Lock info: <{lock.get_lock_info()}>")
|
|
429
439
|
|
|
430
440
|
elif args.Command == "state":
|
|
431
|
-
lock.is_locked()
|
|
441
|
+
print (f"<{args.LockName}> Currently locked: <{lock.is_locked()}>, Lock info: <{lock.get_lock_info()}>")
|
|
432
442
|
|
|
433
443
|
elif args.Command == "trace":
|
|
434
444
|
while True:
|
|
435
|
-
lock.is_locked()
|
|
445
|
+
print (f"<{args.LockName} Currently locked: <{lock.is_locked()}>, Lock info: <{lock.get_lock_info()}>")
|
|
436
446
|
sleep (args.update)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|