Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
multiprocessing-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
multiprocessing-examples
Commits
8a63727b
Commit
8a63727b
authored
4 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
real hard work
parent
23237951
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
example-1/master.py
+1
-1
1 addition, 1 deletion
example-1/master.py
example-1/minion.py
+5
-3
5 additions, 3 deletions
example-1/minion.py
example-1/work.py
+24
-0
24 additions, 0 deletions
example-1/work.py
with
30 additions
and
4 deletions
example-1/master.py
+
1
−
1
View file @
8a63727b
...
...
@@ -9,7 +9,7 @@ from manager import QueueClient
class
Master
(
QueueClient
):
def
run
(
self
):
while
True
:
task
=
random
.
randint
(
5
,
1e
3
)
task
=
random
.
randint
(
5
,
1e
4
)
print
(
'
new task:
'
,
task
)
self
.
queue
.
put
(
task
)
print
(
'
tasks left:
'
,
self
.
queue
.
qsize
())
...
...
This diff is collapsed.
Click to expand it.
example-1/minion.py
+
5
−
3
View file @
8a63727b
...
...
@@ -4,15 +4,17 @@ import random
import
time
from
manager
import
QueueClient
from
work
import
find_prime
class
Minion
(
QueueClient
):
def
run
(
self
):
while
True
:
task
=
self
.
queue
.
get
()
print
(
'
start work on task
'
,
task
,
'
...
'
)
time
.
sleep
(
random
.
randint
(
5
,
15
))
# insert hard work here
print
(
'
work done for task
'
,
task
)
start
=
time
.
perf_counter
()
print
(
f
'
start work on task
{
task
}
...
'
)
result
=
find_prime
(
task
)
print
(
f
'
Done ! The
{
task
}
-th prime number is
{
result
}
(found in
{
time
.
perf_counter
()
-
start
:
.
3
f
}
s)
'
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
example-1/work.py
0 → 100755
+
24
−
0
View file @
8a63727b
#!/usr/bin/env python3
"""
Hard work here. Not efficient, but hard.
"""
def
is_prime
(
number
:
int
)
->
bool
:
"""
Check if a number is prime.
"""
return
not
any
(
number
%
i
==
0
for
i
in
range
(
2
,
number
))
def
find_prime
(
goal
:
int
=
10
,
verbose
:
bool
=
False
)
->
int
:
"""
Find the goal-th prime number.
"""
found
=
0
i
=
1
# let's enumerate all numbers
while
found
<
goal
:
# until we have enough prime ones.
i
+=
1
if
is_prime
(
i
):
found
+=
1
if
verbose
:
print
(
'
the prime number n°
'
,
found
,
'
is
'
,
i
)
return
i
if
__name__
==
'
__main__
'
:
print
(
find_prime
(
50
,
verbose
=
True
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment