Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flamenco-worker-python
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
flamenco-worker-python
Commits
4492405a
Commit
4492405a
authored
Nov 13, 2018
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Don't late-import psutil and other modules
Early detection of missing dependencies trumps a few ms of startup time.
parent
17709f1c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
flamenco_worker/commands.py
+7
-21
7 additions, 21 deletions
flamenco_worker/commands.py
with
7 additions
and
21 deletions
flamenco_worker/commands.py
+
7
−
21
View file @
4492405a
...
...
@@ -3,14 +3,20 @@
import
abc
import
asyncio
import
asyncio.subprocess
import
datetime
import
logging
import
pathlib
import
re
import
shlex
import
shutil
import
subprocess
import
tempfile
import
time
import
typing
from
pathlib
import
Path
import
attr
import
psutil
from
.
import
worker
...
...
@@ -241,13 +247,11 @@ class SleepCommand(AbstractCommand):
def
_timestamped_path
(
path
:
Path
)
->
Path
:
"""
Returns the path with its modification time appended to the name.
"""
from
datetime
import
datetime
mtime
=
path
.
stat
().
st_mtime
# Round away the milliseconds, as those aren't all that interesting.
# Uniqueness is ensured by calling _unique_path().
mdatetime
=
datetime
.
fromtimestamp
(
round
(
mtime
))
mdatetime
=
datetime
.
datetime
.
fromtimestamp
(
round
(
mtime
))
# Make the ISO-8601 timestamp a bit more eye- and filename-friendly.
iso
=
mdatetime
.
isoformat
().
replace
(
'
T
'
,
'
_
'
).
replace
(
'
:
'
,
''
)
...
...
@@ -259,8 +263,6 @@ def _timestamped_path(path: Path) -> Path:
def
_unique_path
(
path
:
Path
)
->
Path
:
"""
Returns the path, or if it exists, the path with a unique suffix.
"""
import
re
suf_re
=
re
.
compile
(
r
'
~([0-9]+)$
'
)
# See which suffixes are in use
...
...
@@ -376,7 +378,6 @@ class CopyFileCommand(AbstractCommand):
self
.
command_name
,
dest
.
parent
)
dest
.
parent
.
mkdir
(
parents
=
True
)
import
shutil
shutil
.
copy
(
str
(
src
),
str
(
dest
))
self
.
worker
.
output_produced
(
dest
)
...
...
@@ -403,7 +404,6 @@ class RemoveTreeCommand(AbstractCommand):
await
self
.
worker
.
register_log
(
msg
)
if
path
.
is_dir
():
import
shutil
shutil
.
rmtree
(
str
(
path
))
else
:
path
.
unlink
()
...
...
@@ -444,8 +444,6 @@ class AbstractSubprocessCommand(AbstractCommand):
pid
=
int
(
pid_str
)
self
.
_log
.
warning
(
'
Found PID file %s with PID %r
'
,
pidfile
,
pid
)
import
psutil
try
:
proc
=
psutil
.
Process
(
pid
)
except
psutil
.
NoSuchProcess
:
...
...
@@ -455,9 +453,6 @@ class AbstractSubprocessCommand(AbstractCommand):
return
'
Subprocess from %s is still running: %s
'
%
(
pidfile
,
proc
)
async
def
subprocess
(
self
,
args
:
list
):
import
subprocess
import
shlex
cmd_to_log
=
'
'
.
join
(
shlex
.
quote
(
s
)
for
s
in
args
)
self
.
_log
.
info
(
'
Executing %s
'
,
cmd_to_log
)
await
self
.
worker
.
register_log
(
'
Executing %s
'
,
cmd_to_log
)
...
...
@@ -578,7 +573,6 @@ class ExecCommand(AbstractSubprocessCommand):
return
super
().
validate
(
settings
)
async
def
execute
(
self
,
settings
:
dict
):
import
shlex
await
self
.
subprocess
(
shlex
.
split
(
settings
[
'
cmd
'
]))
...
...
@@ -613,8 +607,6 @@ class BlenderRenderCommand(AbstractSubprocessCommand):
self
.
re_file_saved
=
re
.
compile
(
r
"
Saved:
'
(?P<filename>.*)
'"
)
def
validate
(
self
,
settings
:
dict
):
import
shlex
blender_cmd
,
err
=
self
.
_setting
(
settings
,
'
blender_cmd
'
,
True
)
if
err
:
return
err
...
...
@@ -780,8 +772,6 @@ class BlenderRenderProgressiveCommand(BlenderRenderCommand):
@command_executor
(
'
merge_progressive_renders
'
)
class
MergeProgressiveRendersCommand
(
AbstractSubprocessCommand
):
def
validate
(
self
,
settings
:
dict
):
import
shlex
blender_cmd
,
err
=
self
.
_setting
(
settings
,
'
blender_cmd
'
,
True
)
if
err
:
return
err
...
...
@@ -817,8 +807,6 @@ class MergeProgressiveRendersCommand(AbstractSubprocessCommand):
return
super
().
validate
(
settings
)
async
def
execute
(
self
,
settings
:
dict
):
import
tempfile
blendpath
=
Path
(
__file__
).
with_name
(
'
merge-exr.blend
'
)
cmd
=
settings
[
'
blender_cmd
'
][:]
...
...
@@ -856,8 +844,6 @@ class MergeProgressiveRendersCommand(AbstractSubprocessCommand):
async
def
move
(
self
,
src
:
Path
,
dst
:
Path
):
"""
Moves a file to another location.
"""
import
shutil
self
.
_log
.
info
(
'
Moving %s to %s
'
,
src
,
dst
)
assert
src
.
is_file
()
...
...
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