track.utils package¶
Submodules¶
track.utils.delay module¶
-
class
track.utils.delay.DelayedCall(fun, kwargs)[source]¶ Bases:
objectDelay a call until later
Methods
__call__(self, \*args, \*\*kwargs)Call self as a function. add_arguments get_future
track.utils.encrypted module¶
-
class
track.utils.encrypted.EncryptedSocket(*args, **kwargs)[source]¶ Bases:
socket.socketSocket with an encrypted layer
Attributes: familyRead-only access to the address family for this socket.
protothe socket protocol
timeoutthe socket timeout
typeRead-only access to the socket type.
Methods
accept(self)Accept an incoming connection & initialize the encryption layer for that client bind(address)Bind the socket to a local address. close()Close the socket. connect(address)Connect the socket to a remote address. connect_ex()This is like connect(address), but returns an error code (the errno value) instead of raising an exception when an error occurs. detach(self)Close the socket object without closing the underlying file descriptor. dup(self)Duplicate the socket. fileno()Return the integer file descriptor of the socket. get_inheritable(self)Get the inheritable flag of the socket getblocking()Returns True if socket is in blocking mode, or False if it is in non-blocking mode. getpeername()Return the address of the remote endpoint. getsockname()Return the address of the local endpoint. getsockopt()Get a socket option. gettimeout()Returns the timeout in seconds (float) associated with socket operations. listen([backlog])Enable a server to accept connections. makefile(self[, mode, buffering, encoding, …])The arguments are as for io.open() after the filename, except the only supported mode values are ‘r’ (default), ‘w’ and ‘b’. recv(self, buffersize, flags[, context])Receive up to buffersize bytes from the socket. recv_into()A version of recv() that stores its data into a buffer rather than creating a new string. recvfrom(buffersize[, flags])Like recv(buffersize, flags) but also return the sender’s address info. recvfrom_into(buffer[, nbytes[, flags]])Like recv_into(buffer[, nbytes[, flags]]) but also return the sender’s address info. recvmsg(bufsize[, ancbufsize[, flags]])Receive normal data (up to bufsize bytes) and ancillary data from the socket. recvmsg_into(buffers[, ancbufsize[, flags]])Receive normal data and ancillary data from the socket, scattering the non-ancillary data into a series of buffers. send(self, data, flags)Send a data string to the socket. sendall(data[, flags])Send a data string to the socket. sendfile(self, file[, offset, count])Send a file until EOF is reached by using high-performance os.sendfile() and return the total number of bytes which were sent. sendmsg()Send normal and ancillary data to the socket, gathering the non-ancillary data from a series of buffers and concatenating it into a single message. sendmsg_afalg([msg], *, op[, iv[, assoclen[)Set operation mode, IV and length of associated data for an AF_ALG operation socket. sendto()Like send(data, flags) but allows specifying the destination address. set_inheritable(self, inheritable)Set the inheritable flag of the socket setblocking(flag)Set the socket to blocking (flag is true) or non-blocking (false). setsockopt(level, option, value, option, …)Set a socket option. settimeout(timeout)Set a timeout on socket operations. shutdown(flag)Shut down the reading side of the socket (flag == SHUT_RD), the writing side of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR). readsize -
accept(self)[source]¶ Accept an incoming connection & initialize the encryption layer for that client
Returns: - returns (socket, addr) of the client
-
recv(self, buffersize, flags: int = 0, context=None)[source]¶ Receive up to buffersize bytes from the socket. For the optional flags argument, see the Unix manual. When no data is available, block until at least one byte is available or until the remote end is closed. When the remote end is closed and all data is read, return the empty string.
track.utils.eta module¶
-
class
track.utils.eta.EstimatedTime(stat_timer: track.utils.stat.StatStream, total: Union[int, List[int]], start: int = 0, name: str = None)[source]¶ Bases:
objectCompute estimated time to arrival given average time and remaining steps
Examples
>>> timer = StatStream() >>> total = (10, 1000) >>> eta = EstimatedTime(timer, total) >>> eta.estimate_time((1, 2))
Attributes: - total
Methods
count(item[, offset])Return the current iteration it given the completion of each steps elapsed(self, unit)Return the elapsed time since the class was created estimated_time(self, step, unit)Estimate the time remaining before the end of the computation set_totals(self, t)Set the total number of iteration for each step show_eta(self, step[, msg, show])Print the estimate time until the processing is done -
static
count(item, offset=0)[source]¶ Return the current iteration it given the completion of each steps
-
estimated_time(self, step: int, unit: int = 60)[source]¶ Estimate the time remaining before the end of the computation
-
show_eta(self, step, msg='', show=True)[source]¶ Print the estimate time until the processing is done
-
total¶
track.utils.log module¶
track.utils.out module¶
track.utils.signal module¶
track.utils.stat module¶
-
class
track.utils.stat.StatStream(drop_first_obs=10)[source]¶ Bases:
objectSharable object
Store the sum of the observations amd the the sum of the observations squared The first few observations are discarded (usually slower than the rest)
The average and the standard deviation is computed at the user’s request
In order to make the computation stable we store the first observation and subtract it to every other observations. The idea is if x ~ N(mu, sigma) x - x0 and the sum of x - x0 should be close(r) to 0 allowing for greater precision; without that trick
varwas getting negative on some iteration.Attributes: - avg
- count
- current_count
- current_obs
- drop_obs
- first_obs
- max
- min
- sd
- sum
- sum_sqr
- total
- val
- var
Methods
from_dict state_dict to_array to_dict to_json update -
avg¶
-
count¶
-
current_count¶
-
current_obs¶
-
drop_obs¶
-
first_obs¶
-
max¶
-
min¶
-
sd¶
-
sum¶
-
sum_sqr¶
-
total¶
-
val¶
-
var¶
-
class
track.utils.stat.StatStreamStruct[source]¶ Bases:
_ctypes.StructureAttributes: - current_count
Structure/Union member
- current_obs
Structure/Union member
- drop_obs
Structure/Union member
- first_obs
Structure/Union member
- max
Structure/Union member
- min
Structure/Union member
- sum
Structure/Union member
- sum_sqr
Structure/Union member
-
current_count¶ Structure/Union member
-
current_obs¶ Structure/Union member
-
drop_obs¶ Structure/Union member
-
first_obs¶ Structure/Union member
-
max¶ Structure/Union member
-
min¶ Structure/Union member
-
sum¶ Structure/Union member
-
sum_sqr¶ Structure/Union member
track.utils.throttle module¶
-
class
track.utils.throttle.ThrottleRepeatedCalls(fun: Callable[[A], R], every=10)[source]¶ Bases:
objectLimit how often the function fun is called in number of times called
Methods
__call__(self, \*args, \*\*kwargs)Call self as a function.
-
class
track.utils.throttle.Throttler(fun: Callable[[A], R], throttle=1)[source]¶ Bases:
objectLimit how often the function fun is called by calling it only every throttle time it has been called
Methods
__call__(self, \*args, \*\*kwargs)Call self as a function.
-
class
track.utils.throttle.TimeThrottler(fun: Callable[[A], R], every=10)[source]¶ Bases:
objectLimit how often the function fun is called in seconds
Methods
__call__(self, \*args, \*\*kwargs)Call self as a function.