SyncStringο
- class thread_factory.concurrency.sync_types.sync_string.SyncString(initial='')[source]ο
Bases:
ISyncA thread-safe mutable wrapper around Pythonβs built-in immutable str.
π Core Purposeο
Provides synchronized access to common string operations and behaviors using internal locking. Useful for concurrent environments where safe string manipulation is required.
π§ Featuresο
Thread-safe string access and mutation.
Supports method forwarding for many built-in string methods.
Can be safely used in multithreaded programs.
- β Recommended Usage:
shared = SyncString(βinitβ) shared.get() # Read thread-safely shared.set(βnew valβ) # Write thread-safely shared.append(ββ¦β) # Custom string manipulation methods
- capitalize(*args, **kwargs)[source]ο
Return a copy of the string with its first character capitalized and the rest lowercased.
Thread-safe: Acquires internal lock during access.
- casefold(*args, **kwargs)[source]ο
Return a casefolded copy of the string, more aggressive than lower() for caseless matching.
Thread-safe: Acquires internal lock during access.
- center(*args, **kwargs)[source]ο
Return a centered string of given width with optional fill character (default is space).
Thread-safe: Acquires internal lock during access.
- count(*args, **kwargs)[source]ο
Return the number of non-overlapping occurrences of a substring in the string.
Thread-safe: Acquires internal lock during access.
- encode(*args, **kwargs)[source]ο
Encode the string using the codec registered for encoding. Default is βutf-8β.
Thread-safe: Acquires internal lock during access.
- endswith(*args, **kwargs)[source]ο
Return True if the string ends with the specified suffix; False otherwise.
Thread-safe: Acquires internal lock during access.
- expandtabs(*args, **kwargs)[source]ο
Return a copy where all tab characters are replaced by spaces using tabsize (default 8).
Thread-safe: Acquires internal lock during access.
- find(*args, **kwargs)[source]ο
Return the lowest index where the substring is found; -1 if not found.
Thread-safe: Acquires internal lock during access.
- format(*args, **kwargs)[source]ο
Perform a string formatting operation using format specifiers.
Thread-safe: Acquires internal lock during access.
- format_map(*args, **kwargs)[source]ο
Similar to format(), but uses a single mapping argument instead of positional and keyword.
Thread-safe: Acquires internal lock during access.
- get() str[source]ο
Return the current string value.
- Returns:
The current string value held by this object.
- Return type:
str
This method acquires the internal lock before reading the value. It is the thread-safe equivalent of accessing the string directly.
- index(*args, **kwargs)[source]ο
Return the lowest index where the substring is found.
Same as str.index(). Raises ValueError if the substring is not found.
This method is thread-safe.
- isalnum(*args, **kwargs)[source]ο
Return True if the string is nonempty and all characters are alphanumeric.
Thread-safe variant of str.isalnum().
- isalpha(*args, **kwargs)[source]ο
Return True if the string is nonempty and all characters are alphabetic.
Thread-safe variant of str.isalpha().
- isascii(*args, **kwargs)[source]ο
Return True if all characters in the string are ASCII.
Thread-safe version of str.isascii().
- isdecimal(*args, **kwargs)[source]ο
Return True if the string is nonempty and all characters are decimal characters.
Thread-safe wrapper around str.isdecimal().
- isdigit(*args, **kwargs)[source]ο
Return True if all characters in the string are digits.
Thread-safe variant of str.isdigit().
- isidentifier(*args, **kwargs)[source]ο
Return True if the string is a valid Python identifier.
Thread-safe version of str.isidentifier().
- islower(*args, **kwargs)[source]ο
Return True if all cased characters are lowercase and the string has at least one cased character.
Thread-safe variant of str.islower().
- isnumeric(*args, **kwargs)[source]ο
Return True if all characters in the string are numeric characters.
Thread-safe version of str.isnumeric().
- isprintable(*args, **kwargs)[source]ο
Return True if all characters are printable or the string is empty.
Thread-safe wrapper around str.isprintable().
- isspace(*args, **kwargs)[source]ο
Return True if all characters in the string are whitespace and the string is nonempty.
Thread-safe variant of str.isspace().
- istitle(*args, **kwargs)[source]ο
Return True if the string is titlecased (i.e. upper-case letters followed by lower-case letters).
Thread-safe wrapper around str.istitle().
- isupper(*args, **kwargs)[source]ο
Return True if all cased characters are uppercase and there is at least one cased character. Thread-safe.
- join(*args, **kwargs)[source]ο
Concatenate any number of strings using the current string as a separator. Thread-safe.
Equivalent to: s.join(iterable)
- ljust(*args, **kwargs)[source]ο
Return the string left-justified in a string of given width. Thread-safe.
Equivalent to: s.ljust(width[, fillchar])
- lstrip(*args, **kwargs)[source]ο
Return a copy of the string with leading whitespace removed.
Thread-safe.
- maketrans(*args, **kwargs)[source]ο
Return a translation table usable for str.translate(). Thread-safe.
Can be used as: str.maketrans(x[, y[, z]])
- partition(*args, **kwargs)[source]ο
Split the string at the first occurrence of sep, and return a 3-tuple. Thread-safe.
Equivalent to: s.partition(sep)
- removeprefix(*args, **kwargs)[source]ο
Return a string with the specified prefix removed if present. Thread-safe.
Equivalent to: s.removeprefix(prefix)
- removesuffix(*args, **kwargs)[source]ο
Return a string with the specified suffix removed if present. Thread-safe.
Equivalent to: s.removesuffix(suffix)
- replace(*args, **kwargs)[source]ο
Return a copy with all occurrences of substring replaced by another. Thread-safe.
Equivalent to: s.replace(old, new[, count])
- rfind(*args, **kwargs)[source]ο
Return the highest index where the substring is found, or -1 if not found. Thread-safe.
Equivalent to: s.rfind(sub[, start[, end]])
- rindex(*args, **kwargs)[source]ο
Return the highest index where the substring is found, or raise ValueError. Thread-safe.
Equivalent to: s.rindex(sub[, start[, end]])
- rjust(*args, **kwargs)[source]ο
Return the string right-justified in a string of given width. Thread-safe.
Equivalent to: s.rjust(width[, fillchar])
- rpartition(*args, **kwargs)[source]ο
Return a 3-tuple where the string is split around the last occurrence of the separator.
If the separator is found, returns (head, sep, tail). If not, returns (ββ, ββ, original). Thread-safe.
- rsplit(*args, **kwargs)[source]ο
Return a list of the words in the string, using sep as the delimiter string.
Performs a right split. If maxsplit is given, splits at most maxsplit times. Thread-safe.
- rstrip(*args, **kwargs)[source]ο
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead. Thread-safe.
- set(new_value: str)[source]ο
Set a new string value.
- Parameters:
new_value (str) β The new value to assign to the internal string.
This method acquires the internal lock before updating the value. It allows atomic replacement of the internal string in concurrent settings.
- split(*args, **kwargs)[source]ο
Return a list of the words in the string, using sep as the delimiter string.
If sep is not specified or is None, any whitespace string is a separator. Thread-safe.
- splitlines(*args, **kwargs)[source]ο
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included unless keepends is given and True. Thread-safe.
- startswith(*args, **kwargs)[source]ο
Return True if the string starts with the specified prefix.
Can be limited by optional start and end arguments. Thread-safe.
- strip(*args, **kwargs)[source]ο
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead. Thread-safe.
- swapcase(*args, **kwargs)[source]ο
Return a copy of the string with uppercase characters converted to lowercase and vice versa.
Thread-safe.
- title(*args, **kwargs)[source]ο
Return a titlecased version of the string.
Words start with uppercase characters, all remaining characters are lowercase. Thread-safe.