some simple examples: threading and logging

This commit is contained in:
Mari Wahl 2014-12-31 10:34:43 -05:00
parent 045e2cc061
commit c3d315eb4f
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
__author__ = "bt3"
import logging
LOG_FILENAME = 'logging_example.out'
logging.basicConfig(filename=LOG_FILENAME,
level=logging.DEBUG,
)
logging.debug('This message should go to the log file')
f = open(LOG_FILENAME, 'rt')
try:
body = f.read()
finally:
f.close()
print 'FILE:'
print body

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
__author__ = "bt3"
import threading
def worker(num):
"""thread worker function"""
print 'Worker: %s' % num
return
threads = []
for i in range(5):
t = threading.Thread(target=worker, args=(i,))
threads.append(t)
t.start()