I have been using taskpools for parallel processing. Recently I updated taskpools v0.0.4 to taskpools v0.1.0 and now my nim program throws a value error. It was working till yesterday before update.I am unable to understand the reason for this. Here is the nim script and error
import ./Model_V16.nim
import taskpools, cpuinfo
var
dfile: string = ""
sDateP1: string = "31/03/2023" # for NB Run
sDateP: string = "31/03/2025"
sDateC: string = "31/03/2026"
dates: seq[string]
dfile = "../Data/Data_Curr_F.csv"
dates = @[sDateP1, sDateP, sDateC]
# with eb_nb=1, indv = 2 and c_oner = 1 a new file can be written with onerous indicator for individual records
# choose run from 1 to 8 for sensitivity
proc liabApprox(tp: Taskpool, n: int, ebnb: int): int =
var pendingFuts = newSeq[Flowvar[int]](n)
if ebnb == 1:
for k in 0..(n-1):
pendingFuts[k] = tp.spawn val_run(run = k, eb_nb = ebnb, indv = 0,
c_oner = 0, dfile, dates, expvar = 0, err_check = 0)
elif ebnb == 0:
for k in 0..(n-1):
pendingFuts[k] = tp.spawn val_run(run = k, eb_nb = ebnb, indv = 0,
c_oner = 0, dfile, dates, expvar = 0, err_check = 0)
result = n
proc main() =
var ebnb = 0
var n = 1
if ebnb == 1:
n = 1
# var nthreads = countProcessors()
var tp = Taskpool.new(num_threads = n) # Default to the number of hardware threads.
echo tp.liabApprox(n, ebnb)
# tp.syncAll()
# Block until all pending tasks are processed (implied in tp.shutdown())
tp.shutdown()
main()
Here is the error on compilation of program
nim c --opt:speed --hints:on --d:release --styleCheck:usages --styleCheck:hint --threads:on -r "2024_CA.nim" (in directory: /home/ajayc/Documents/Work/IFRS/CALI/Mar_26/WorkSpace)
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
....................................................................................................
/home/ajayc/.nimble/pkgs2/nimblas-0.3.1-e1ecdea4bb8176f12d66efd4aa0c7b3bea970027/nimblas/private/common.nim(52, 7) Hint: Using BLAS library matching pattern: lib(blas|cblas|openblas).so(|.3|.2|.1|.0) [User]
........................................................................................................................................................................
/home/ajayc/.nimble/pkgs2/nimlapack-0.3.1-fcb25795c6fb43f9251b7f34c3ad84c39e645afd/nimlapack.nim(20, 7) Hint: Using LAPACK library matching pattern: liblapack.so(|.3|.2|.1|.0) [User]
.................................................................
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(67, 30) Hint: 'parseint' should be: 'parseInt' [func declared in /usr/lib/nim/lib/pure/strutils.nim(1151, 6)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(82, 9) Hint: 'repYr' should be: 'repyr' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(67, 9)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(82, 17) Hint: 'repYr' should be: 'repyr' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(67, 9)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(566, 66) Hint: 'vGen' should be: 'vGEN' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(129, 30)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(1260, 66) Hint: 'vDB_iFCF_t' should be: 'vDB_ifCF_t' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(102, 36)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(1261, 41) Hint: 'vExp_ifCF_t' should be: 'vEXP_ifCF_t' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(102, 49)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(1261, 60) Hint: 'vPrem_IFCF_t' should be: 'vPrem_ifCF_t' [var declared in /Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(102, 9)] [Name]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(1234, 43) Hint: 'lra' is declared but not used [XDeclaredButNotUsed]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(103, 32) Hint: 'vDB_CF_t' is declared but not used [XDeclaredButNotUsed]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(103, 41) Hint: 'vMB_CF_t' is declared but not used [XDeclaredButNotUsed]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(103, 51) Hint: 'vEXP_CF_t' is declared but not used [XDeclaredButNotUsed]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(103, 61) Hint: 'vSV_CF_t' is declared but not used [XDeclaredButNotUsed]
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_Model_V16.nim(105, 103) Hint: 'vPV_FCF_t' is declared but not used [XDeclaredButNotUsed]
..................
/Documents/Work/IFRS/CALI/Mar_26/WorkSpace/IFRS_2024_CA.nim(25, 26) template/generic instantiation of `spawn` from here
/home/ajayc/.nimble/pkgs2/taskpools-0.1.0-09e1b2fdad55b973724d61227971afc0df0b7a81/taskpools/taskpools.nim(502, 70) template/generic instantiation of `toTask` from here
/home/ajayc/.nimble/pkgs2/taskpools-0.1.0-09e1b2fdad55b973724d61227971afc0df0b7a81/taskpools/tasks.nim(216, 65) template/generic instantiation from here
/home/ajayc/.nimble/pkgs2/taskpools-0.1.0-09e1b2fdad55b973724d61227971afc0df0b7a81/taskpools/tasks.nim(119, 20) Error: taskpool_val_run(run_570425667, eb_nb_570425669, indv_570425671, c_oner_570425673, dfile_570425675, dates_570425677, expvar_570425679, err_check_570425681,
fut_570425683) can raise an unlisted exception: ValueError
Compilation failed. The last line of error is listing fut_570425683 as parameter although it is not part of the proc val_run().
Please help to resolve this.
It was working till yesterday before update.
Somewhere between 0.0.4 and 0.1.0 taskpools library was updated to check exceptions more strictly, e.g. see this commit: https://github.com/status-im/nim-taskpools/commit/20677645212a544007763cb99c9faca10db657d6
- pendingFuts[k] = tp.spawn val_run(run = k, eb_nb = ebnb, indv = 0,
- c_oner = 0, dfile, dates, expvar = 0, err_check = 0)
You should make sure that val_run cannot raise, handle all possible exceptions with try except.
import pkg/taskpools
proc foo(n: int): float =
if n > 100: raise new ValueError
return 42
proc fooSafe(n: int): float {.raises: [].}=
try:
if n > 100: raise new ValueError
except ValueError:
return -1
return 42
proc main() =
var tp = Taskpool.new(num_threads = 4)
echo sync tp.spawn foo(1) # can raise -> error
echo sync tp.spawn fooSafe(1) # cannot raise -> works
tp.syncAll()
tp.shutdown()
main()
The last line of error is listing fut_570425683 as parameter although it is not part of the proc val_run().
Taskpools' spawn is a macro that rewrites your proc, taskpool_val_run is a generated procedure.