Quick actions

cmd+k|ctrl+k

Navigation

Languages

evenodd threads

Snippet info

Language

Python

Visibility

public

Author

arthurpc02

Created

2026-06-04T16:23:11.080368Z

Updated

2026-06-04T23:21:43.272607Z

# currently not working


import threading

class thread(threading.Thread):
    sync_flag = 1
    def __init__(self, thread_name, thread_ID):
        threading.Thread.__init__(self)
        self.thread_name = thread_name 
        self.thread_ID = thread_ID

    def run(self):
        if self.thread_ID == 1:
            for i in range(1,10):
                if (i % 2) == 1: #odd
                    if sync_flag == 1:
                        print(i)
                        sync_flag = "even"


print("Hello World!")
thread_odd = thread("odd", 1)
thread_even = thread("even", 2)

thread_odd.start()
thread_even.start()


print("Good bye world")
INFO