Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
6b769bca
Commit
6b769bca
authored
Nov 30, 2023
by
comfyanonymous
Browse files
Do a garbage collect after the interval even if nothing is running.
parent
7f469203
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
18 deletions
+33
-18
execution.py
execution.py
+4
-2
main.py
main.py
+29
-16
No files found.
execution.py
View file @
6b769bca
...
@@ -700,10 +700,12 @@ class PromptQueue:
...
@@ -700,10 +700,12 @@ class PromptQueue:
self
.
server
.
queue_updated
()
self
.
server
.
queue_updated
()
self
.
not_empty
.
notify
()
self
.
not_empty
.
notify
()
def
get
(
self
):
def
get
(
self
,
timeout
=
None
):
with
self
.
not_empty
:
with
self
.
not_empty
:
while
len
(
self
.
queue
)
==
0
:
while
len
(
self
.
queue
)
==
0
:
self
.
not_empty
.
wait
()
self
.
not_empty
.
wait
(
timeout
=
timeout
)
if
timeout
is
not
None
and
len
(
self
.
queue
)
==
0
:
return
None
item
=
heapq
.
heappop
(
self
.
queue
)
item
=
heapq
.
heappop
(
self
.
queue
)
i
=
self
.
task_counter
i
=
self
.
task_counter
self
.
currently_running
[
i
]
=
copy
.
deepcopy
(
item
)
self
.
currently_running
[
i
]
=
copy
.
deepcopy
(
item
)
...
...
main.py
View file @
6b769bca
...
@@ -89,23 +89,36 @@ def cuda_malloc_warning():
...
@@ -89,23 +89,36 @@ def cuda_malloc_warning():
def
prompt_worker
(
q
,
server
):
def
prompt_worker
(
q
,
server
):
e
=
execution
.
PromptExecutor
(
server
)
e
=
execution
.
PromptExecutor
(
server
)
last_gc_collect
=
0
last_gc_collect
=
0
need_gc
=
False
gc_collect_interval
=
10.0
while
True
:
while
True
:
item
,
item_id
=
q
.
get
()
timeout
=
None
execution_start_time
=
time
.
perf_counter
()
if
need_gc
:
prompt_id
=
item
[
1
]
timeout
=
max
(
gc_collect_interval
-
(
current_time
-
last_gc_collect
),
0.0
)
e
.
execute
(
item
[
2
],
prompt_id
,
item
[
3
],
item
[
4
])
q
.
task_done
(
item_id
,
e
.
outputs_ui
)
queue_item
=
q
.
get
(
timeout
=
timeout
)
if
server
.
client_id
is
not
None
:
if
queue_item
is
not
None
:
server
.
send_sync
(
"executing"
,
{
"node"
:
None
,
"prompt_id"
:
prompt_id
},
server
.
client_id
)
item
,
item_id
=
queue_item
execution_start_time
=
time
.
perf_counter
()
current_time
=
time
.
perf_counter
()
prompt_id
=
item
[
1
]
execution_time
=
current_time
-
execution_start_time
e
.
execute
(
item
[
2
],
prompt_id
,
item
[
3
],
item
[
4
])
print
(
"Prompt executed in {:.2f} seconds"
.
format
(
execution_time
))
need_gc
=
True
if
(
current_time
-
last_gc_collect
)
>
10.0
:
q
.
task_done
(
item_id
,
e
.
outputs_ui
)
gc
.
collect
()
if
server
.
client_id
is
not
None
:
comfy
.
model_management
.
soft_empty_cache
()
server
.
send_sync
(
"executing"
,
{
"node"
:
None
,
"prompt_id"
:
prompt_id
},
server
.
client_id
)
last_gc_collect
=
current_time
print
(
"gc collect"
)
current_time
=
time
.
perf_counter
()
execution_time
=
current_time
-
execution_start_time
print
(
"Prompt executed in {:.2f} seconds"
.
format
(
execution_time
))
if
need_gc
:
current_time
=
time
.
perf_counter
()
if
(
current_time
-
last_gc_collect
)
>
gc_collect_interval
:
gc
.
collect
()
comfy
.
model_management
.
soft_empty_cache
()
last_gc_collect
=
current_time
need_gc
=
False
async
def
run
(
server
,
address
=
''
,
port
=
8188
,
verbose
=
True
,
call_on_start
=
None
):
async
def
run
(
server
,
address
=
''
,
port
=
8188
,
verbose
=
True
,
call_on_start
=
None
):
await
asyncio
.
gather
(
server
.
start
(
address
,
port
,
verbose
,
call_on_start
),
server
.
publish_loop
())
await
asyncio
.
gather
(
server
.
start
(
address
,
port
,
verbose
,
call_on_start
),
server
.
publish_loop
())
...
...
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