Patch a bug in the printing of the progress bar leading to a bus error

when compiled with some C compilers and Cython >= 0.24
This commit is contained in:
2016-08-03 10:12:23 +02:00
parent 000b9999ad
commit ccc877764e

View File

@ -7,7 +7,9 @@ Created on 27 mars 2016
'''
import sys
from ..utils cimport bytes2str
from ..utils import bytes2str,str2bytes
from .config cimport getConfiguration
cdef class ProgressBar:
cdef clock_t clock(self):
@ -23,7 +25,7 @@ cdef class ProgressBar:
def __init__(self,
off_t maxi,
dict config,
dict config={},
str head="",
double seconde=0.1):
self.starttime = self.clock()
@ -34,14 +36,18 @@ cdef class ProgressBar:
self.arrow = 0
self.lastlog = 0
if not config:
config=getConfiguration()
self.ontty = sys.stderr.isatty()
if (maxi<=0):
maxi=1
self.maxi = maxi
self.head = str2bytes(head)
self.chead= self.head
self._head = str2bytes(head)
self.chead= self._head
self.logger=config[config["__root_config__"]]["logger"]
@ -104,35 +110,43 @@ cdef class ProgressBar:
if self.ontty:
fraction=<int>(percent * 50.)
self.arrow=(self.arrow+1) % 4
self.diese[fraction]=0
self.spaces[50 - fraction]=0
if days:
<void>fprintf(stderr,b'\r%s %5.1f %% |%s%c%s] remain : %d days %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %d days %02d:%02d:%02d',
self.chead,
percent*100,
self.diese,self.wheel[self.arrow],self.spaces,
fraction,self.diese,
self.wheel[self.arrow],
50-fraction,self.spaces,
days,hour,minu,sec)
else:
<void>fprintf(stderr,b'\r%s %5.1f %% |%s%c%s] remain : %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %02d:%02d:%02d',
self.chead,
percent*100.,
self.diese,self.wheel[self.arrow],self.spaces,
fraction,self.diese,
self.wheel[self.arrow],
50-fraction,self.spaces,
hour,minu,sec)
self.diese[fraction]=b'#'
self.spaces[50 - fraction]=b' '
twentyth = int(percent * 20)
if twentyth != self.lastlog:
tenth = int(percent * 10)
if tenth != self.lastlog:
if self.ontty:
<void>fputs(b'\n',stderr)
self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % (
bytes2str(self.head),
bytes2str(self._head),
percent*100.,
hour,minu,sec))
self.lastlog=twentyth
self.lastlog=tenth
else:
self.cycle+=1
property head:
def __get__(self):
return self._head
def __set__(self,str value):
self._head=str2bytes(value)
self.chead=self._head