Skip to content

Instantly share code, notes, and snippets.

@samukasmk
Forked from zeldani/thread1.py
Last active August 29, 2015 14:27

Revisions

  1. @zeldani zeldani created this gist Feb 27, 2014.
    20 changes: 20 additions & 0 deletions thread1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/python:
    import thread
    import time

    def print_time (nomedothread, delay):
    conta = 0
    while conta < 5:
    time.sleep(delay)
    conta += 1
    print "%s: %s" % (nomedothread, time.ctime(time.time()) )

    # Criando o thread:
    try:
    thread.start_new_thread( print_time, ("Thread-1", 2, ) )
    thread.start_new_thread( print_time, ("Thread-2", 4, ) )
    except:
    print "Erro: nao foi possivel iniciar o thread."

    while 1:
    pass