forked from lastmile-ai/aiconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3/n] Restart Editor Servers on Python Interpreter Change
- Loading branch information
Ryan Holinshead
committed
Feb 23, 2024
1 parent
e11e1a6
commit 7f54a1e
Showing
7 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Mutex } from "async-mutex"; | ||
import { getPortPromise } from "portfinder"; | ||
|
||
/** | ||
* Super simple class to manage server port allocation using a lock mechanism. If | ||
* we don't do this, restarting multiple servers simultaneously can result in | ||
* obtaining the same port for multiple servers. | ||
*/ | ||
class ServerPortManager { | ||
private lock; | ||
|
||
constructor() { | ||
this.lock = new Mutex(); | ||
} | ||
|
||
async getPort(): Promise<number> { | ||
const release = await this.lock.acquire(); | ||
const port = await getPortPromise(); | ||
release(); | ||
return port; | ||
} | ||
} | ||
|
||
const serverPortManager = new ServerPortManager(); | ||
export default serverPortManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters