Skip to content

Instantly share code, notes, and snippets.

@keitheis
Created August 27, 2016 06:40
Show Gist options
  • Save keitheis/6ca219899aa78f3d27e1e657007bbb3e to your computer and use it in GitHub Desktop.
Save keitheis/6ca219899aa78f3d27e1e657007bbb3e to your computer and use it in GitHub Desktop.
import logging
logging.basicConfig(level=logging.INFO)
import alog
from threading import Thread
from multiprocessing import Process
def make_log(name, x):
def logging():
for i in range(5):
alog.info("{} logging {}:{}".format(name, x, i))
return logging
def make_logger(name, x):
def log():
for i in range(5):
logger = logging.getLogger(name)
logger.info("logging {}:{}".format(name, x, i))
return log
ts = []
ps = []
for i in range(4):
t = Thread(None, make_log("T", i))
p = Process(target=make_log("P", i))
ts.append(t)
ps.append(p)
for t, p in zip(ts, ps):
t.start()
p.start()
"""
💰 pyx t.py
2016-08-27 12:45:08,868 INFO [t:9] loging 0:0
2016-08-27 12:45:08,869 INFO [t:9] loging 0:1
2016-08-27 12:45:08,869 INFO [t:9] loging 0:0
2016-08-27 12:45:08,870 INFO [t:9] loging 0:1
2016-08-27 12:45:08,870 INFO [t:9] loging 0:2
2016-08-27 12:45:08,870 INFO [t:9] loging 0:2
2016-08-27 12:45:08,871 INFO [t:9] loging 0:3
2016-08-27 12:45:08,871 INFO [t:9] loging 0:3
2016-08-27 12:45:08,871 INFO [t:9] loging 0:4
2016-08-27 12:45:08,871 INFO [t:9] loging 0:4
2016-08-27 12:45:08,871 INFO [t:9] loging 1:0
2016-08-27 12:45:08,872 INFO [t:9] loging 1:1
2016-08-27 12:45:08,873 INFO [t:9] loging 1:2
2016-08-27 12:45:08,873 INFO [t:9] loging 2:0
2016-08-27 12:45:08,874 INFO [t:9] loging 1:3
2016-08-27 12:45:08,874 INFO [t:9] loging 2:1
2016-08-27 12:45:08,875 INFO [t:9] loging 3:0
2016-08-27 12:45:08,876 INFO [t:9] loging 1:4
2016-08-27 12:45:08,876 INFO [t:9] loging 2:2
2016-08-27 12:45:08,876 INFO [t:9] loging 3:1
2016-08-27 12:45:08,876 INFO [t:9] loging 2:3
2016-08-27 12:45:08,876 INFO [t:9] loging 3:2
2016-08-27 12:45:08,877 INFO [t:9] loging 2:4
2016-08-27 12:45:08,877 INFO [t:9] loging 3:3
2016-08-27 12:45:08,877 INFO [t:9] loging 3:4
^CError in atexit._run_exitfuncs:
Process Process-4:
Traceback (most recent call last):
File "/Users/keitheis/opt/conda3/lib/python3.4/multiprocessing/popen_fork.py", line 30, in poll
Traceback (most recent call last):
pid, sts = os.waitpid(self.pid, flag)
KeyboardInterrupt
File "/Users/keitheis/opt/conda3/lib/python3.4/multiprocessing/process.py", line 254, in _bootstrap
self.run()
File "/Users/keitheis/opt/conda3/lib/python3.4/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "t.py", line 9, in logging
alog.info("loging {}:{}".format(x, i))
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 1279, in info
self._log(INFO, msg, args, **kwargs)
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 1414, in _log
self.handle(record)
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 1424, in handle
self.callHandlers(record)
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 1486, in callHandlers
hdlr.handle(record)
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 851, in handle
self.acquire()
File "/Users/keitheis/opt/conda3/lib/python3.4/logging/__init__.py", line 802, in acquire
self.lock.acquire()
KeyboardInterrupt
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment