夏夜暖风

文章 评论 浏览 31

夏夜暖风 2025-02-21 01:41:41

从服务器流式文件数据不允许寻求,因为它是服务器上下文的一次性操作。

要允许寻求服务器需要允许

当您使用 res.sendfile() 发送文件数据。

如果要渲染一个带有音频播放器的网页,则需要添加(至少)两个处理程序:一个用于HTML文件,一个用于音频文件。如果您只是使用常规的plain html文件,则可以使用中间件,您指出包含HTML文件的目录。

Streaming file data from the server doesn't allow for seeking because it's a one-off operation from the context of the server.

To enable seeking the server needs to allow HTTP range requests, where a client tells it that it wants to receive a part of a download (starting at byte X, ending at byte Y, the "range" part).

Express support such requests when you use res.sendFile() to send the file data.

If you want to render a web page with an audio player, you need to add (at least) two handlers: one for the HTML file, and one for the audio file. If you're just using regular plain HTML files, you can use the express.static() middleware, which you point to a directory that contains your HTML files.

使用.pipe(res)将音频发送给客户端是否允许您寻找?

夏夜暖风 2025-02-20 15:41:22

您可以使用 tf.stack

import tensorflow as tf

@tf.function
def join_tns_num(tensor, num):
    return tf.stack([tensor, tf.constant(num)], axis=0)

检查功能:

>>> join_tns_num(tf.constant(3), 2)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([3, 2], dtype=int32)>

You can use tf.stack.

import tensorflow as tf

@tf.function
def join_tns_num(tensor, num):
    return tf.stack([tensor, tf.constant(num)], axis=0)

Check function:

>>> join_tns_num(tf.constant(3), 2)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([3, 2], dtype=int32)>

如何从tf.constant和数字等其他张量中创建张量?

夏夜暖风 2025-02-20 12:34:20

您可以以这种方式清除选择:

private void DataGrid_SelectionChanged(Object sender, EventArgs e)
{
    DataGrid.ClearSelection(); 
}

You could clear the selection this way:

private void DataGrid_SelectionChanged(Object sender, EventArgs e)
{
    DataGrid.ClearSelection(); 
}

当数据网格单元单击时,禁用整个行的选择

夏夜暖风 2025-02-20 10:50:46

确保您也更改模式: chmod -r u+rwx db

Make sure you change the mode too: chmod -R u+rwX db

许可拒绝 @ dir_initialize ruby​​ on Rails

夏夜暖风 2025-02-20 06:20:14

您应该尝试使用对象而不是数组,然后按这样的用户ID存储用户详细信息:

{1: User, 2: User, 3: User}

然后,您可以通过其ID获取其ID,而无需每次循环浏览数组

You should try to use an object instead of array, and store the user details by the user id like this:

{1: User, 2: User, 3: User}

and then you can just get the user by its id without having to loop through the array every time

在ReactJ中有什么特定的方法可以处理大型循环?

夏夜暖风 2025-02-20 04:50:31

如果我正确理解的话,您要设置一个多项目workspace
您基本上将拥有一个定义工作区或根项目的单个 angular.json 文件,然后您将拥有子项目。

接下来,您可以定义一个带有模块的儿童项目,作为图书馆。您不必发布它即可使用它。您可以在您的应用程序中使用该库

最后,另一个解决方案是使您的项目完全分开。在这种情况下,您可以使用 ng-paackagr 将角模块作为单独的库提取。在这种情况下,请参见本教程关于如何做。

If I understood correctly, you want to set up a multi-project workspace.
You will basically have a single angular.json file that defines a workspace or root project, in which then you will have the child projects.

Next, you can define one of the child projects, the one with the module, to be a library. You don't have to publish it to use it. You can use that library inside your application.

Lastly, another solution is to have your projects completely separated. In that case, you can use ng-paackagr to extract the Angular module as a separate library. In that case, see this tutorial on how to do it.

在同一工作空间中的单独的Express项目中的导入角模块

夏夜暖风 2025-02-20 01:50:22

方法 MoveFocus(FocusDirection) 不能这样访问。

obain实例: val focusmanager = localfocusmanager.current and
然后使用该实例: focusmanager.movefocus(focusDirection.down)

这在 @composable
的范围内工作,目标需求 modifier.focusable()

Method moveFocus(FocusDirection) cannot be accessed like that.

Obain an instance: val focusManager = LocalFocusManager.current and
then use that instance: focusManager.moveFocus(FocusDirection.Down).

This works within the scope of a @Composable
and the target needs Modifier.focusable().

未解决的参考:MoveFocus

夏夜暖风 2025-02-19 19:11:08

从我的有限反应经验中,当发生这种有趣的事情时,我有一些尝试尝试的方法。其中之一是在将功能传递为道具时调用空功能。 IE而不是:

<MealComponentForMagicDiary
            diary={diary}
            setDiary={setDiary}
            index={index}
          />

尝试:

<MealComponentForMagicDiary
            diary={diary}
            setDiary={() => setDiary}
            index={index}
          />

我很想知道为什么有时会起作用,如果有人(有人吗?)理解正确的反应。

我的手指交叉,它适合您!

From my limited react experience, when funny things like this happen I have a few go-to methods to try. One of them is to call an empty function when passing a function down as a prop. I.e. instead of:

<MealComponentForMagicDiary
            diary={diary}
            setDiary={setDiary}
            index={index}
          />

try:

<MealComponentForMagicDiary
            diary={diary}
            setDiary={() => setDiary}
            index={index}
          />

I'd love to know why this works sometimes, if anybody (does anybody?) understands react properly.

My fingers are crossed that it works for you!

React JSX拒绝在UI中显示更新的状态

夏夜暖风 2025-02-19 09:28:24

您生成的假图像的数量取决于您采样的噪声向量的大小。理想情况下,在训练的单个步骤中,您将采样dimension batch_size x Noings_dim 的噪声向量,然后使用生成器生成 batch_size face>伪造图像。同样,您的歧视者会看到 batch_size 真实图像的数量。

这样,在每个步骤中,您的歧视者都会看到相等数量的假和真实图像,而歧视者看到的假图像总数将等于训练集中的图像总数本身。

The number of fake images that you generate depends on the size of the noise vector that you sample. Ideally, in a single step of training, you would sample a noise vector of dimension batch_size x noise_dim and use the generator to generate batch_size fake images. Similarly, your discriminator would see the batch_size number of real images.

This way, at every step, your discriminator sees an equal number of fake and real images, and the total number of fake images seen by your discriminator would be equal to the total number of images in your training set itself.

训练gan需要多少个假示例?

夏夜暖风 2025-02-18 18:36:51

联合全部

select trial, start_date, end_date, start_date as date, 'start' marker_start_end from table1
union all
select trial, start_date, end_date, end_date as date, 'end' marker_start_end from table1

unnest case

select trial, start_date, end_date, 
case when a.num = 1 then start_date else end_date end date, 
case when a.num = 1 then 'start' else 'end' end marker_start_end from
(
select trial, start_date, end_date, 
unnest(array[1,2]) num from table1
) a

隐藏<代码> JOIN (但仍在加入)

select 
  trial, 
  start_date, 
  end_date, 
  case when a.num = 1 then start_date else end_date end date, 
  marker_start_end 
from table1, (values(1,'start'),(2, 'end')) a(num,marker_start_end)

UNION ALL

select trial, start_date, end_date, start_date as date, 'start' marker_start_end from table1
union all
select trial, start_date, end_date, end_date as date, 'end' marker_start_end from table1

UNNEST with CASE

select trial, start_date, end_date, 
case when a.num = 1 then start_date else end_date end date, 
case when a.num = 1 then 'start' else 'end' end marker_start_end from
(
select trial, start_date, end_date, 
unnest(array[1,2]) num from table1
) a

Hidden JOIN (but still join)

select 
  trial, 
  start_date, 
  end_date, 
  case when a.num = 1 then start_date else end_date end date, 
  marker_start_end 
from table1, (values(1,'start'),(2, 'end')) a(num,marker_start_end)

Db fiddle

根据PostgreSQL中的其他列值创建其他列

夏夜暖风 2025-02-18 09:38:45

其小的语法误差应为n*m数组。因此,您需要将其转换为数组。这是代码。

import pandas as pd
import numpy as np
import scipy

#obs = df[['tablename1', 'tablename2']].to_numpy()
      #OR
obs = np.array(df[['tablename1', 'tablename2']])
test= scipy.stats.contingency.association(obs,method='tschuprow')
print(test)

希望,这将解决错误。

Its small syntax error, observed should be n*m array. So, you need to convert it to array. Here is the code.

import pandas as pd
import numpy as np
import scipy

#obs = df[['tablename1', 'tablename2']].to_numpy()
      #OR
obs = np.array(df[['tablename1', 'tablename2']])
test= scipy.stats.contingency.association(obs,method='tschuprow')
print(test)

Hope, this will solve the error.

tschuprow关联错误 - 模块&#x27; scipy.stats.contingency&#x27;没有属性&#x27;协会&#x27;

夏夜暖风 2025-02-18 07:50:47

它帮助我添加到Run()方法:

environment.admin()
            .addServlet("metrics", new MetricsServlet(environment.metrics()))
            .addMapping("/metrics");

It helped me to add to the run() method:

environment.admin()
            .addServlet("metrics", new MetricsServlet(environment.metrics()))
            .addMapping("/metrics");

如何将指标暴露于Dropwizard中的HTTP?

夏夜暖风 2025-02-18 05:23:31

我有点惊讶前两个示例起作用。 strcpy 将第二个参数指向的字符阵列将其复制到第一个参数指向的字符数组。

在您的第一个示例中,指针名称 AltName 没有指向任何内容。它们是非直接的指针。现在,当执行 main 函数或只是编译器决定初始化它们时,它们具有基于内存中的任何内容的值。这就是为什么我惊讶于您的代码没有崩溃的原因。

无论如何,您的第三个示例是segfaulting的原因是,您将两个指针都设置为字符串文字(即,“ hi” “ andandstring” )。字符串文字(很可能)存储在仅读取的内存部分中。因此,当您运行 strcpy 将目标指针设置为 altname 时,您正在尝试写入仅阅读内存。这是对内存的无效使用,因此崩溃了。您的第四个例子也是如此。

在最后一个示例中,您的问题是 n 未终止。 strcpy 继续复制字符,直到达到终结器(即,'\ 0'')。您已将'C'和a 'b'放在数组中,但没有终结器。因此, strcpy 即使达到 n 的末尾,也将继续复制。当 sizeof(s)大于8时,它起作用的事实可能涉及堆栈中存在的空字节。也就是说,如果您使 s 太小,您将在其末端编写并损坏堆栈上的内存。您可能会覆盖返回指针,从而在执行功能后返回到一些无效的内存地址。

您需要做的是使用指针,而是使用数组。这将为您提供可写入的记忆部分所需的存储空间。您还需要确保阵列为无效。可以通过使用字符串文字初始化阵列来自动完成。

char name[] = "HI";
char altname[] = "randomstring";
strcpy(altname, name);
char s[3]; // Enough space to hold "cb" plus a null-terminator.
char n[] = "cb";
char *name = n;
char *altname = s;
strcpy(altname, name);

I'm a bit surprised that the first two examples worked. strcpy takes the character array pointed to by the second argument and copies it to the character array pointed to by the first argument.

In your first example, the pointers name and altname aren't pointing to anything. They're uninitialized pointers. Now they have some value based on either whatever gunk was in memory when the main function was executed or just however the compiler decided to initialize them. That's why I'm surprised that your code isn't crashing.

Anyway, the reason why your third example is segfaulting is you've set both pointers to point to string literals (i.e., "HI" and "randomstring"). String literals are (most likely) stored in a read-only section of memory. So, when you run strcpy with the destination pointer set to altname, you're trying to write to read-only memory. That's an invalid use of memory and hence the crash. The same goes for your fourth example.

In the final example, your problem is that n is not null-terminated. strcpy keeps copying characters until it reaches a terminator (i.e., '\0'). You've put a 'c' and a 'b' in your array but no terminator. Therefore, strcpy is going to keep copying even after it's reached the end of n. The fact that it works when sizeof(s) is greater than 8 probably involves where a null byte happens to exist on your stack. That is, if you make s too small, you'll write past the end of it and corrupt the memory on your stack. It's possible you're overriding your return pointer and thus returning to some invalid memory address when your function is done executing.

What you need to do is, instead of using pointers, use arrays. This will give you the storage space you need in a writable section of memory. You also need to make sure that your arrays are null-terminated. This can be done automatically by initializing your arrays with string literals.

char name[] = "HI";
char altname[] = "randomstring";
strcpy(altname, name);
char s[3]; // Enough space to hold "cb" plus a null-terminator.
char n[] = "cb";
char *name = n;
char *altname = s;
strcpy(altname, name);

内存分配如何与字符指针(字符串文字,数组)一起使用?

夏夜暖风 2025-02-18 03:44:46

将此存储库克隆到新位置,发现更多的文件更改了。
原来我有.gitattributes文件。删除它之后 - 更改的文件消失了

Cloned this repository to new location and found many more files changed.
Turns out I had .gitattributes file. After I deleted it - the changed files went away

git使文件未分布

夏夜暖风 2025-02-17 16:35:15

基本上,您遇到此错误的原因是因为多处理使用 pickle 通常,通常仅序列化模块级函数。功能 addi 不是顶级模块级功能。实际上,线全局addi 没有做任何事情,因为 addi 从未在外部模块中声明。因此,您有三种解决此问题的方法。

方法1

您可以在执行 calc 函数之前在全局范围中定义 addi

import multiprocessing as mp
import os


def addi(num1, num2):
    print(num1 + num2)

def calc(num1, num2):

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

output

here is main 9924
11

方法2

您可以切换到多进程,它使用而不是泡菜,可以序列化此类功能。

import multiprocess as mp  # Note that we are importing "multiprocess", no "ing"!
import os

def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

输出

here is main 67632
11

方法2b

当它是一个有用的库时,您可能不想使用 Multiprocess 有一些有效的理由。一个很大的事实是,标准库的多处理,并且该叉子彼此不兼容(尤其是如果您在Subpackage Multiprocessing.managers.managers 中使用任何内容)。这意味着,如果您在自己的项目中使用此叉子,同时也使用第三方库,这些库本人使用标准库的多次浏览,则可能会看到意外的行为。

无论如何,如果您想坚持使用标准库的多处理而不使用叉子,则可以使用 dill 自己来序列化python闭合,例如函数 addi 通过划分 Process 类并添加我们自己的一些逻辑。下面给出了一个示例:

import dill
from multiprocessing import Process  # Use the standard library only
import os

class DillProcess(Process):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._target = dill.dumps(self._target)  # Save the target function as bytes, using dill

    def run(self):
        if self._target:
            self._target = dill.loads(self._target)    # Unpickle the target function before executing
            self._target(*self._args, **self._kwargs)  # Execute the target function


def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    m = DillProcess(target=addi, args=(num1, num2))  # Note how we use DillProcess, and not multiprocessing.Process
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

输出

here is main 23360
11

方法3

此方法适用于那些不能使用代码中任何第三方库的人。我建议您在诉诸于该方法之前确保上述方法不起作用,因为它有点骇客,您确实需要重组一些代码。

无论如何,此方法通过在顶部模块范围中引用您的本地功能来起作用,以便它们可以通过泡菜访问。为了动态执行此操作,我们创建一个占位符类,并将所有本地函数添加为其类属性。我们还需要确保函数' __ Qualname __ 属性已更改为指向其新位置,并且所有这些都在之外完成(如果__ -name __ ... block(否则新启动的过程不会看到属性)。在此处考虑您的代码的稍微修改的版本:

import multiprocessing as mp
import os

def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    # Another local function you might have
    def addi2():
        print('hahahaha')

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

以下是您可以使用上述详细方法使其正常工作的方法:

import multiprocessing as mp
import os


# This is our placeholder class, all local functions will be added as it's attributes
class _LocalFunctions:
    @classmethod
    def add_functions(cls, *args):
        for function in args:
            setattr(cls, function.__name__, function)
            function.__qualname__ = cls.__qualname__ + '.' + function.__name__


def calc(num1, num2, _init=False):
    # The _init parameter is to initialize all local functions outside __main__ block without actually running the 
    # whole function. Basically, you shift all local function definitions to the top and add them to our 
    # _LocalFunctions class. Now, if the _init parameter is True, then this means that the function call was just to 
    # initialize the local functions and you SHOULD NOT do anything else. This means that after they are initialized,
    # you simply return (check below)

    def addi(num1, num2):
        print(num1 + num2)

    # Another local function you might have
    def addi2():
        print('hahahaha')

    # Add all functions to _LocalFunctions class, separating each with a comma:
    _LocalFunctions.add_functions(addi, addi2)

    # IMPORTANT: return and don't actually execute the logic of the function if _init is True!
    if _init is True:
        return

    # Beyond here is where you put the function's actual logic including any assertions, etc.
    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


# All factory functions must be initialized BEFORE the "if __name__ ..." clause. If they require any parameters,
# substitute with bogus ones and make sure to put the _init parameter value as True!
calc(0, 0, _init=True)

if __name__ == '__main__':
    a = calc(5, 6)

因此,您需要更改代码中的一些内容如果__ -name__ ... 子句,需要初始化顶部和所有工厂功能(他们需要接受 _Init 参数)。但这可能是如果您不能使用莳萝,可以做到最好。

Basically, the reason you are getting this error is because multiprocessing uses pickle, which can only serialize top-module level functions in general. Function addi is not a top-module level function. In fact, the line global addi is not doing anything because addi has never been declared in the outer module. So you have three ways to fix this.

Method 1

You can define addi in the global scope before executing calc function:

import multiprocessing as mp
import os


def addi(num1, num2):
    print(num1 + num2)

def calc(num1, num2):

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

Output

here is main 9924
11

Method 2

You can switch to multiprocess, which uses dill instead of pickle, and can serialize such functions.

import multiprocess as mp  # Note that we are importing "multiprocess", no "ing"!
import os

def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

Output

here is main 67632
11

Method 2b

While it's a useful library, there are a few valid reasons why you may not want to use multiprocess. A big one is the fact that the standard library's multiprocessing and this fork are not compatible with each other (especially if you use anything from within the subpackage multiprocessing.managers). This means that if you are using this fork in your own project, but also use third-party libraries which themselves use the standard library's multiprocesing instead, you may see unexpected behaviour.

Anyway, in cases where you want to stick with the standard library's multiprocessing and not use the fork, you can use dill yourself to serialize python closures like the function addi by subclassing the Process class and adding some of our own logic. An example is given below:

import dill
from multiprocessing import Process  # Use the standard library only
import os

class DillProcess(Process):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._target = dill.dumps(self._target)  # Save the target function as bytes, using dill

    def run(self):
        if self._target:
            self._target = dill.loads(self._target)    # Unpickle the target function before executing
            self._target(*self._args, **self._kwargs)  # Execute the target function


def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    m = DillProcess(target=addi, args=(num1, num2))  # Note how we use DillProcess, and not multiprocessing.Process
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

Output

here is main 23360
11

Method 3

This method is for those who cannot use any third-party libraries in their code. I will recommend making sure that the above methods did not work before resorting to this one because it's a little hacky and you do need to restructure some of your code.

Anyways, this method works by referencing your local functions in the top-module scope, so that they become accessible by pickle. To do this dynamically, we create a placeholder class and add all the local functions as its class attributes. We would also need to make sure that the functions' __qualname__ attribute is altered to point to their new location, and that this all is done every run outside the if __name__ ... block (otherwise newly started processes won't see the attributes). Consider a slightly modified version of your code here:

import multiprocessing as mp
import os

def calc(num1, num2):

    def addi(num1, num2):
        print(num1 + num2)

    # Another local function you might have
    def addi2():
        print('hahahaha')

    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


if __name__ == "__main__":
    # creating processes
    calc(5, 6)

Below is a how you can make it work by using the above detailed method:

import multiprocessing as mp
import os


# This is our placeholder class, all local functions will be added as it's attributes
class _LocalFunctions:
    @classmethod
    def add_functions(cls, *args):
        for function in args:
            setattr(cls, function.__name__, function)
            function.__qualname__ = cls.__qualname__ + '.' + function.__name__


def calc(num1, num2, _init=False):
    # The _init parameter is to initialize all local functions outside __main__ block without actually running the 
    # whole function. Basically, you shift all local function definitions to the top and add them to our 
    # _LocalFunctions class. Now, if the _init parameter is True, then this means that the function call was just to 
    # initialize the local functions and you SHOULD NOT do anything else. This means that after they are initialized,
    # you simply return (check below)

    def addi(num1, num2):
        print(num1 + num2)

    # Another local function you might have
    def addi2():
        print('hahahaha')

    # Add all functions to _LocalFunctions class, separating each with a comma:
    _LocalFunctions.add_functions(addi, addi2)

    # IMPORTANT: return and don't actually execute the logic of the function if _init is True!
    if _init is True:
        return

    # Beyond here is where you put the function's actual logic including any assertions, etc.
    m = mp.Process(target=addi, args=(num1, num2))
    m.start()

    print("here is main", os.getpid())
    m.join()


# All factory functions must be initialized BEFORE the "if __name__ ..." clause. If they require any parameters,
# substitute with bogus ones and make sure to put the _init parameter value as True!
calc(0, 0, _init=True)

if __name__ == '__main__':
    a = calc(5, 6)

So there are a few things you would need to change in your code, namely that all local functions inside are defined at the top and all factory functions need to be initialized (for which they need to accept the _init parameter) outside the if __name__ ... clause. But this is probably the best you can do if you can't use dill.

attributeError:多处理中的泡菜本地对象可以

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文