multiprocess
This module enables parallelism in Dinfio. You can run multiple processes simultaneously. This is useful for intensive operations, like Networking, File IO, Computation, etc.
process_arguments
— This constant stores arguments that can be consumed by a child process
clear_done_callback()
— Clear callback when all processes are finished runningpack()
— Pack any value into a string. This is useful when you want to pass array or simple object to the parent/child process. This function is a wrapper of json.encode({packed: ...})
. Warning: this function is now deprecated, and will be removed on the future releaseprocess()
— Run .fio file in a separate process (child process)process_return()
— Return a value to parent process and terminate the child processprocess_yield()
— Yield a value to parent processset_done_callback()
— Set callback when all processes are finished runningtotal_cpu()
— Get the number of logical CPUs in the systemunpack()
— Unpack a packed string from the parent/child process. This function is a wrapper of json.decode(...)
. Warning: this function is now deprecated, and will be removed on the future releasevoid()
— A void function. Use this function if you don't want to add callback to your process. Warning: this function is now deprecated, and will be removed on the future release. Please use nothing
instead if you don't want to add callback to your processThere are no classes.
import multiprocess
start
process("child_1")
process("child_2", [23], on_updated(), on_returned(), on_finished())
stop
function on_updated(data)
writeln("Updated data from child #2: " & data)
stop
function on_returned(data)
writeln("Returned data from child #2: " & data)
stop
function on_finished()
writeln("Child #2 finished")
stop
' Child #1 - child_1.fio
import multiprocess
start
writeln("Child #1 started")
sleep(2000)
writeln("Child #1 finished")
stop
' Child #2 - child_2.fio
import multiprocess
start
n = process_arguments[0]
process_yield(n * 2)
process_return(n ^ 2)
stop
' Example output:
'
' Child #1 started
' Updated data from child #2: 46
' Returned data from child #2: 529
' Child #2 finished
' Child #1 finished