Hi Timo,
Yesterday I experimented a lot with both Python and workers (and failed).
Here is an example. In this code I want the workers to be started as background tasks, so the program should first print "This should be printed first", then each worker (each started with random delay interval) shoud print its own message. This obviously doesn't happen because of the queue.Sync() call but I don't want to wait for all the workers to complete.
Class DelayedTest Extends %RegisteredObject
{
ClassMethod Callback(interval As %String) As %Status
{
Hang interval
Write "Interval = ", interval, !
Return $$$OK
}
Method RunWorkers()
{
#Dim queue as %SYSTEM.WorkMgr
Set queue = ##class(%SYSTEM.WorkMgr).%New()
For i = 1:1:5
{
Set status = queue.Queue("..Callback", $RANDOM(5) + 1) // Minimal delay is 1 second
$$$ThrowOnError(status)
}
Set status = queue.Sync()
$$$ThrowOnError(status)
}
ClassMethod Main()
{
#Dim d = ##class(DelayedTest).%New()
Do d.RunWorkers()
Write "This should be printed first"
}
}
Also, I'm not sure that Hang is appropriate here to emulate some delay. If it works like Sleep it should block the main thread.
- Log in to post comments