List API:

Module shared_atomic

class shared_atomic.atomic_list. atomic_list ( initial : Iterable , encoding = 'utf-8' , mode = 'singleprocessing' , windows_unix_compatibility : bool = False )

List provide atomic operations, the list should be no longer than 8 bytes

:attributes encoding: readonly string character set

initial_length: readonly total length in bits

value: read/write value of the list

int_value: readonly int value

size: readonly size of the list

mode: readonly ‘s’ for single process, ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported

constructor to initialize the set, the set should be no longer than 8 bytes

Parameters
  • initial – initial value of the set, if the initial value is longer than 8 bytes, please specify the trimming target length, or else it would fail.n

  • mode – the mode in which the set will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported, setting it to ‘m’ or ‘multiprocessing’ will be ignored.n

  • encoding – , character set, default ‘utf-8’n

  • windows_unix_compatibility – whether the source code should be compatible with windows x64

change_mode ( newmode = 'm' , windows_unix_compatibility : bool = False )

Switch between singleprocessing mode and multiprocessing mode, the contents will be copied , other threads/processes would not be aware of the change.

Parameters
  • newmode – the mode to change to, ‘m’ for multiproessing, ‘s’ for singleprocessing. default ‘m’

  • windows_unix_compatibility – if change to multiprocessing mode, whether the source code should be compatible with windows x64

Returns

None

decode ( bits_in_bytes : bytes ) list

Function to decode the bytes to set

Parameters
  • bits_in_bytes – bytes needs to be decoded

  • encoding – character encoding

Returns

the decoded list

encode ( input_list : list )

function to encode the input_set with specific character encoding

Parameters
  • input_list – input set

  • encoding – character encoding

Returns

(data in integer representation, total length in bits)

get_int ( ) size_t

Get the whole integer representation from the set, the whole list would be treated as a large integer

Returns

the integer representation

get_list ( ) list

Get the list atomically

Returns

the list

property int_value : size_t

same with get_int

list_compare_and_set ( i , n : list ) bool

Compare and list atomically, This compares the contents of self with the contents of i. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, the operation is a read and the current contents of itself are written into i.

Parameters
  • i – the list to be compared with

  • n – another bytes to be ready to set to self if comparision return True

Returns

if self is equal to i return True, else return False

list_compare_and_set_value ( i : list , n : list ) list

Compare and swap atomically, This compares the contents of self with the contents of n. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, No operation is performed.

Parameters
  • i – exchange value

  • n – The value to be compared with

Returns

the initial value of self

list_get_and_set ( data : list ) list

Get and set atomically

Parameters

data – new data to set

Returns

the original list

list_shift ( i , j )

Value exchange between 3 atomic_lists in 2 groups atomically, store i in itself after store itself in j

Parameters
  • i – one atomic_list

  • j – another atomic_list

Returns

None

list_store ( i )

Atomically store contents from another list to this list, if the other list is different with this one in size , the function will fail.

Parameters

i – another list to store its value to self

Returns

None

reencode ( newencode : unicode )

Change the encoding of the atomic_list, if the original size is not enough, it will elongate the list, which is only valid in the master process/thread, if 8 bytes are not enough, it will fail.

Parameters

newencode – new encoding, such as ‘utf-8’, ‘utf-16-le’

Returns

None

set_int ( integer : size_t )

Set the whole integer representation from the set, the whole list would be treated as a large integer

Returns

None

set_list ( data : list )

Set the value in the list, if the new data is longer than the original size of the list. it will expand the set accordingly which could only be used in the master process/thread the size of the set can be checked with self.size

Parameters

data – input list

Returns

None

shift_and_add ( data_prefix : size_t , accumulate_length : char , input_length : char , kind : char )

Function to finish the shift and add of the data prefix

Parameters
  • data_prefix – integer for the data_prefix

  • accumulate_length – total data length in bits accumulated so far

  • input_length – length of the data segment in bits

  • kind – sorts of data

Returns

(data_prefix, accumulate_length)

property value : list

same with get_list and set_list