atomic api Example with multiprocessing and multiple threads::ΒΆ

You need the following steps to utilize the module:

  1. create function used by child processes, refer to UIntAPIs, IntAPIs, BytearrayAPIs, StringAPIs, SetAPIs, ListAPIs, in each process, you can create multiple threads. On macOS, before the main process start, please set environment variable OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES, to alliviate Python bug

    def process_run(a):

         def subthread_run(a):


         threadlist = []

         for t in range(5000):

             threadlist.append(Thread(target=subthread_run, args=(a,)))

         for t in range(5000):


         for t in range(5000):


  2. create the shared bytearray

        a = atomic_bytearray(b'ab', length=7, paddingdirection='r', paddingbytes=b'012', mode='m')

  3. start processes/threads to utilize the shared bytearray

        processlist = []

        for p in range(2):

            processlist.append(Process(target=process_run, args=(a,)))

        for p in range(2):


        for p in range(2):


        assert a.value == int.to_bytes(27411031864108609,length=8,byteorder='big')