track.utils package

Submodules

track.utils.debug module

track.utils.debug.print_stack(msg='--')[source]

track.utils.delay module

class track.utils.delay.DelayedCall(fun, kwargs)[source]

Bases: object

Delay a call until later

Methods

__call__(self, \*args, \*\*kwargs) Call self as a function.
add_arguments  
get_future  
add_arguments(self, **kwargs)[source]
get_future(self)[source]
class track.utils.delay.Future(promise)[source]

Bases: object

Methods

get  
is_ready  
get(self)[source]
is_ready(self)[source]
exception track.utils.delay.FutureIsNotReady[source]

Bases: Exception

track.utils.delay.delay_call(fun, **kwargs)[source]
track.utils.delay.is_delayed_call(obj)[source]

track.utils.encrypted module

class track.utils.encrypted.EncryptedSocket(*args, **kwargs)[source]

Bases: socket.socket

Socket with an encrypted layer

Attributes:
family

Read-only access to the address family for this socket.

proto

the socket protocol

timeout

the socket timeout

type

Read-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
readsize(self)[source]
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.

send(self, data: bytes, flags: int = 0) → int[source]

Send a data string to the socket. For the optional flags argument, see the Unix manual. Return the number of bytes sent; this may be less than len(data) if the network is busy.

sendall(data[, flags])[source]

Send a data string to the socket. For the optional flags argument, see the Unix manual. This calls send() repeatedly until all data is sent. If an error occurs, it’s impossible to tell how much data has been sent.

track.utils.encrypted.wrap_socket(sock, server_side=False, handshaked=False)[source]

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: object

Compute 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

elapsed(self, unit: int = 60)[source]

Return the elapsed time since the class was created

estimated_time(self, step: int, unit: int = 60)[source]

Estimate the time remaining before the end of the computation

set_totals(self, t)[source]

Set the total number of iteration for each step

show_eta(self, step, msg='', show=True)[source]

Print the estimate time until the processing is done

total
track.utils.eta.get_time(time: track.utils.stat.StatStream)[source]
track.utils.eta.to_list(item)[source]

track.utils.log module

track.utils.log.get_log_record_constructor()[source]
track.utils.log.make_logger(name)[source]
track.utils.log.set_log_level(level=20)[source]

track.utils.out module

class track.utils.out.RingOutputDecorator(file=None, n_entries=50)[source]

Bases: object

Methods

flush  
out  
output  
raw  
write  
flush(self)[source]
out(self)[source]
output(self)[source]
raw(self)[source]
write(self, string)[source]

track.utils.signal module

class track.utils.signal.SignalHandler[source]

Bases: object

Methods

atexit  
sigint  
sigterm  
atexit(self)[source]
sigint(self, signum, frame)[source]
sigterm(self, signum, frame)[source]

track.utils.stat module

class track.utils.stat.StatStream(drop_first_obs=10)[source]

Bases: object

Sharable 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 var was 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
static from_dict(data)[source]
max
min
sd
state_dict(self)[source]
sum
sum_sqr
to_array(self, transform=None)[source]
to_dict(self)[source]
to_json(self)[source]
total
update(self, val, weight=1)[source]
val
var
class track.utils.stat.StatStreamStruct[source]

Bases: _ctypes.Structure

Attributes:
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.system module

track.utils.system.get_gpu_name()[source]

track.utils.throttle module

class track.utils.throttle.ThrottleRepeatedCalls(fun: Callable[[A], R], every=10)[source]

Bases: object

Limit 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: object

Limit 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: object

Limit how often the function fun is called in seconds

Methods

__call__(self, \*args, \*\*kwargs) Call self as a function.
track.utils.throttle.is_throttled(fun: Callable[[~A], ~R]) → bool[source]
track.utils.throttle.throttle_repeated(fun: Callable[[~A], ~R], every=None) → Callable[[~A], Union[~R, NoneType]][source]
track.utils.throttle.throttled(fun: Callable[[~A], ~R], throttle=None, every=None) → Callable[[~A], Union[~R, NoneType]][source]

Module contents

exception track.utils.ItemNotFound[source]

Bases: Exception

track.utils.listen_socket(add, port, backend=None)[source]
track.utils.open_socket(add, port, backend=None)[source]