Make operation non-blocking (assuming GIL is released)

This commit is contained in:
Itamar Turner-Trauring 2023-10-23 09:57:32 -04:00
parent 40d649b3b2
commit 101453cd56

View File

@ -14,6 +14,7 @@ from allmydata.interfaces import IMutableFileNode, ICheckable, ICheckResults, \
IMutableFileVersion, IWriteable IMutableFileVersion, IWriteable
from allmydata.util import hashutil, log, consumer, deferredutil, mathutil from allmydata.util import hashutil, log, consumer, deferredutil, mathutil
from allmydata.util.assertutil import precondition from allmydata.util.assertutil import precondition
from allmydata.util.cputhreadpool import defer_to_thread
from allmydata.uri import WriteableSSKFileURI, ReadonlySSKFileURI, \ from allmydata.uri import WriteableSSKFileURI, ReadonlySSKFileURI, \
WriteableMDMFFileURI, ReadonlyMDMFFileURI WriteableMDMFFileURI, ReadonlyMDMFFileURI
from allmydata.monitor import Monitor from allmydata.monitor import Monitor
@ -128,7 +129,8 @@ class MutableFileNode(object):
return self return self
def create_with_keys(self, keypair, contents, @deferredutil.async_to_deferred
async def create_with_keys(self, keypair, contents,
version=SDMF_VERSION): version=SDMF_VERSION):
"""Call this to create a brand-new mutable file. It will create the """Call this to create a brand-new mutable file. It will create the
shares, find homes for them, and upload the initial contents (created shares, find homes for them, and upload the initial contents (created
@ -137,8 +139,8 @@ class MutableFileNode(object):
use) when it completes. use) when it completes.
""" """
self._pubkey, self._privkey = keypair self._pubkey, self._privkey = keypair
self._writekey, self._encprivkey, self._fingerprint = derive_mutable_keys( self._writekey, self._encprivkey, self._fingerprint = await defer_to_thread(
keypair, derive_mutable_keys, keypair
) )
if version == MDMF_VERSION: if version == MDMF_VERSION:
self._uri = WriteableMDMFFileURI(self._writekey, self._fingerprint) self._uri = WriteableMDMFFileURI(self._writekey, self._fingerprint)
@ -149,7 +151,7 @@ class MutableFileNode(object):
self._readkey = self._uri.readkey self._readkey = self._uri.readkey
self._storage_index = self._uri.storage_index self._storage_index = self._uri.storage_index
initial_contents = self._get_initial_contents(contents) initial_contents = self._get_initial_contents(contents)
return self._upload(initial_contents, None) return await self._upload(initial_contents, None)
def _get_initial_contents(self, contents): def _get_initial_contents(self, contents):
if contents is None: if contents is None: