async def gen_nostr_ann_pow(nostr_pubk: bytes, target_bits: int) -> Tuple[int, int]:
    """Generate a PoW for a Nostr announcement. The PoW is hash[b'electrum-'+pubk+nonce]"""
    import multiprocessing  # not available on Android, so we import it here
    hash_function = hashlib.sha256
    hash_len_bits = 256
    max_nonce: int = (1 << (32 * 8)) - 1  # 32-byte nonce
    start_nonce = 0

    max_workers = max(multiprocessing.cpu_count() - 1, 1)  # use all but one CPU
    manager = multiprocessing.Manager()
    shutdown = manager.Event()
    with ProcessPoolExecutor(max_workers=max_workers) as executor:
        tasks = []
        loop = asyncio.get_running_loop()
        for task in range(0, max_workers):
            task = loop.run_in_executor(
                executor,
                nostr_pow_worker,
                start_nonce,
                nostr_pubk,
                target_bits,
                hash_function,
                hash_len_bits,
                shutdown
            )
            tasks.append(task)
            start_nonce += max_nonce // max_workers  # split the nonce range between the processes
            if start_nonce > max_nonce:  # make sure we don't go over the max_nonce
                start_nonce = random.randint(0, int(max_nonce * 0.75))

        done, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
        hash_res, nonce_res = done.pop().result()
        executor.shutdown(wait=False, cancel_futures=True)

    return nonce_res, get_nostr_ann_pow_amount(nostr_pubk, nonce_res)
Generate a PoW for a Nostr announcement. The PoW is hash[b'electrum-'+pubk+nonce]
electrum/util.py