Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
2
2 Semester Practice 2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Щербинин Артем Владимирович
2 Semester Practice 2
Commits
c1c0f8f6
Commit
c1c0f8f6
authored
Jun 21, 2025
by
Щербинин Артем Владимирович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
d3a9bea8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
mult_logger.py
Задание_2.2._ВСР_Щербинин_А._В./mult_logger.py
+41
-0
No files found.
Задание_2.2._ВСР_Щербинин_А._В./mult_logger.py
0 → 100644
View file @
c1c0f8f6
import
threading
from
datetime
import
datetime
import
time
class
Logger
:
_instance
=
None
_lock
=
threading
.
Lock
()
def
__new__
(
cls
):
if
cls
.
_instance
is
None
:
with
cls
.
_lock
:
if
cls
.
_instance
is
None
:
time
.
sleep
(
0.01
)
cls
.
_instance
=
super
(
Logger
,
cls
)
.
__new__
(
cls
)
cls
.
_instance
.
_initialize
()
return
cls
.
_instance
def
_initialize
(
self
):
self
.
log_file
=
open
(
"test.log"
,
"a"
)
def
log
(
self
,
message
):
timestamp
=
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
self
.
log_file
.
write
(
f
"[{timestamp}] {message}
\n
"
)
def
create_instance
(
thread_id
):
logger
=
Logger
()
logger
.
log
(
f
"Message #{thread_id}"
)
if
__name__
==
"__main__"
:
threads
=
[
threading
.
Thread
(
target
=
create_instance
,
args
=
(
i
,))
for
i
in
range
(
10
)]
for
t
in
threads
:
t
.
start
()
# time.sleep(3)
for
t
in
threads
:
t
.
join
()
print
(
"Готово. Все потоки записали лог."
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment