Skip to content

Commit 758cd1c

Browse files
committed
ipython friendly logging
1 parent ee73086 commit 758cd1c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

graphtools/logging.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import logging
55
import time
6+
import sys
67

78

89
__logger_name__ = "graphtools"
@@ -14,11 +15,21 @@ class RSafeStdErr(object):
1415
This class writes directly to stderr to avoid this.
1516
"""
1617

17-
def write(self, msg):
18-
os.write(2, bytes(msg, 'utf8'))
18+
def __init__(self):
19+
try:
20+
__IPYTHON__
21+
self.write = self.write_ipython
22+
except NameError:
23+
self.write = self.write_r_safe
24+
25+
def write_ipython(self, msg):
26+
print(msg, end='', file=sys.stdout)
27+
28+
def write_r_safe(self, msg):
29+
os.write(1, bytes(msg, 'utf8'))
1930

2031
def flush(self):
21-
pass
32+
sys.stdout.flush()
2233

2334

2435
class TaskLogger(object):

0 commit comments

Comments
 (0)