File tree 1 file changed +11
-5
lines changed
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 28
28
import os
29
29
import re
30
30
import openshot
31
+ import socket
31
32
from threading import Thread
32
33
from classes import info
33
34
from classes .query import File
@@ -75,18 +76,23 @@ class httpThumbnailServerThread(Thread):
75
76
""" This class runs a HTTP thumbnail server inside a thread
76
77
so we don't block the main thread with handle_request()."""
77
78
79
+ def find_free_port (self ):
80
+ """Find the first available socket port"""
81
+ s = socket .socket ()
82
+ s .bind (('' , 0 ))
83
+ return s .getsockname ()[1 ]
84
+
78
85
def kill (self ):
79
86
self .running = False
87
+ self .thumbServer .shutdown ()
80
88
81
89
def run (self ):
82
90
self .running = True
83
91
84
- # TODO: Choose availble port
85
- self .server_address = ('127.0.0.1' , 8081 )
92
+ # Start listening for HTTP requests (and check for shutdown every 0.5 seconds)
93
+ self .server_address = ('127.0.0.1' , self . find_free_port () )
86
94
self .thumbServer = httpThumbnailServer (self .server_address , httpThumbnailHandler )
87
-
88
- while self .running :
89
- self .thumbServer .handle_request ()
95
+ self .thumbServer .serve_forever (0.5 )
90
96
91
97
92
98
class httpThumbnailHandler (BaseHTTPRequestHandler ):
You can’t perform that action at this time.
0 commit comments