forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use worker threads for fetching Windows Registry interpreters (#22479)
For #22146
- Loading branch information
Kartik Raj
authored
Nov 16, 2023
1 parent
7a4de92
commit e27185a
Showing
15 changed files
with
182 additions
and
42 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
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
24 changes: 24 additions & 0 deletions
24
src/client/pythonEnvironments/common/registryKeysWorker.ts
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,24 @@ | ||
import { Registry } from 'winreg'; | ||
import { parentPort, workerData } from 'worker_threads'; | ||
import { IRegistryKey } from './windowsRegistry'; | ||
|
||
const WinReg = require('winreg'); | ||
|
||
const regKey = new WinReg(workerData); | ||
|
||
function copyRegistryKeys(keys: IRegistryKey[]): IRegistryKey[] { | ||
// Use the map function to create a new array with copies of the specified properties. | ||
return keys.map((key) => ({ | ||
hive: key.hive, | ||
arch: key.arch, | ||
key: key.key, | ||
})); | ||
} | ||
|
||
regKey.keys((err: Error, res: Registry[]) => { | ||
if (!parentPort) { | ||
throw new Error('Not in a worker thread'); | ||
} | ||
const messageRes = copyRegistryKeys(res); | ||
parentPort.postMessage({ err, res: messageRes }); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/client/pythonEnvironments/common/registryValuesWorker.ts
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,27 @@ | ||
import { RegistryItem } from 'winreg'; | ||
import { parentPort, workerData } from 'worker_threads'; | ||
import { IRegistryValue } from './windowsRegistry'; | ||
|
||
const WinReg = require('winreg'); | ||
|
||
const regKey = new WinReg(workerData); | ||
|
||
function copyRegistryValues(values: IRegistryValue[]): IRegistryValue[] { | ||
// Use the map function to create a new array with copies of the specified properties. | ||
return values.map((value) => ({ | ||
hive: value.hive, | ||
arch: value.arch, | ||
key: value.key, | ||
name: value.name, | ||
type: value.type, | ||
value: value.value, | ||
})); | ||
} | ||
|
||
regKey.values((err: Error, res: RegistryItem[]) => { | ||
if (!parentPort) { | ||
throw new Error('Not in a worker thread'); | ||
} | ||
const messageRes = copyRegistryValues(res); | ||
parentPort.postMessage({ err, res: messageRes }); | ||
}); |
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
Oops, something went wrong.