mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
some simple examples: threading and logging
This commit is contained in:
parent
045e2cc061
commit
c3d315eb4f
@ -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
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user