• 51 Posts
  • 23 Comments
Joined 1 year ago
cake
Cake day: July 13th, 2023

help-circle













  • Some software that enables users to browse all kinds of content and encourages them to donate to creators using cryptocurrency. This program would automatically distribute payments to verified creators who have provided a cryptocurrency address. This ensures that creators receive their rightful compensation for their work.

    At present, I only donate to individual creators who receive funding through platforms like OpenCollective, Patreon, or similar services. I don’t even donate to Lemmy because there are multiple developers, but only one person in charge of receiving and distributing donations and I don’t want to waste time and effort making sure the funds are distributed between everyone involved. I’d instead prefer open-source software that simplifies the process and ensures that everyone receives their fair share.

























  • import asyncio
    from asyncio import Queue
    
    async def read_input(queue: Queue):
        while True:
            user_input = await loop.run_in_executor(None, input, "Enter something: ")
            await queue.put(user_input)
    
    async def process_input(queue: Queue):
        while True:
            user_input = await queue.get()
            if user_input == "quit":
                break
            print(f"Processing input: {user_input}")
            await asyncio.sleep(1) # Simulate processing time
    
    async def main():
        queue = Queue()
        task1 = asyncio.create_task(read_input(queue))
        task2 = asyncio.create_task(process_input(queue))
    
        await asyncio.gather(task1, task2)
    
    if __name__ == "__main__":
        loop = asyncio.get_event_loop()
    
        try:
            loop.run_until_complete(main())
        except KeyboardInterrupt:
            pass
        finally:
            loop.close()
    

    The read_input function acts as a producer, continuously reading input from the command line and putting it into a Queue.

    The process_input function acts as a consumer, taking items from the Queue and processing them. It prints out each input and simulates processing time with asyncio.sleep().

    The main function creates both tasks, runs them concurrently with asyncio.gather(), and handles cleanup of the event loop.

    This allows the producer and consumer to run asynchronously, communicating through the queue. The input call runs in a threadpool executor to avoid blocking the async loop.