首页 \ 问答 \ shmctl锁住共享内存段怎么用?

shmctl锁住共享内存段怎么用?

shmctl(shm_id, SHM_LOCK, &ds) 比如我用这段函数锁定共享内存的。返回值也是0 成功的,但我发现好像没用锁不住。 我在别的程序里用shm_id照样可以存取这片共享内存啊。 到底是怎么回事 还是我理解错 锁定共享内存的概念了?
更新时间:2023-03-20 14:03

最满意答案

python 3里面,bytes存放的是binary data,而str存放的text

从bytes转到str,需要把binary data解码,因此你需要指定一个编码,例如:
my_str = str(my_bytes, encoding="utf-8")

建议阅读文档:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
http://docs.python.org/release/3.0.1/howto/unicode.html#unicode-howto

这两段文档应该足够解决你的困惑,呵呵

其他回答

一、使用工具:python、urllib urlopen
二、方法步骤:
1、首先,编写如下代码:
import socket。
2、然后编写如下代码,设置全局的超时时间为60s。
socket.setdefaulttimeout(60)
3、重新执行就可以了。
三、注意事项:
如果是urllib2就更简单,而且现实中,urllib,urllib2常会一起使用(两者分别提供不同的功能)
html = urllib.urlopen(url).read()
修改为
import urllib2
html = urllib2.urlopen(url, timeout=60).read()

相关问答

更多
  • 1、把python的scripts文件夹加入到环境变量里面 2、运行cmd 3、cd XXX切到程序所在文件夹 4、输入python xxx.py
  • 使用try...except来对urlopen出错进行控制,通过socket模块的setdefaulttimeout函数来控制超时时间,python3.x示例代码如下: import urllib.request import socket socket.setdefaulttimeout(10) #设置超时时间 #要下载的网页列表 urls = ['http://www.test.com/1.htm', 'http://www.test.com/2.htm', 'http://www.test.com/3 ...
  • 这是网络错误的意思,与程序无关,可能是你的网络有问题,或者你要连接的网站与你本地网络的不兼容问题..
  • python 3里面,bytes存放的是binary data,而str存放的text 从bytes转到str,需要把binary data解码,因此你需要指定一个编码,例如: my_str = str(my_bytes, encoding="utf-8") 建议阅读文档: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit http://docs.python.org ...
  • 关于Python的urlopen的使用:   创建一个表示远程url的类文件对象,然后像本地文件一样操作这个类文件对象来获取远程数据。   参数url表示远程数据的路径,一般是网址;参数data表示以post方式提交到url的数据(玩过web的人应该知道提交数据的两种方式:post与get。如果你不清楚,也不必太在意,一般情况下很少用到这个参数);参数proxies用于设置代理。   urlopen返回 一个类文件对象,它提供了如下方法:read() , readline() , readlines() , ...
  • python3x是from urllib.request import urlopen python2x是from urllib2 import urlopen
  • 你已经命名了一个脚本string.py 。 urllib模块导入它,认为它是stdlib中的同一个string模块,然后你的代码在现在部分定义的urllib模块上使用了一个尚不存在的属性。 为其他脚本命名。 You've named a script string.py. The urllib module imports this, thinking that it's the same string module that's in the stdlib, and then your code uses ...
  • 这个问题/答案可能是你的问题。 基本上你的POST请求被重定向到/api/v1.0/payments/(注意结尾的斜杠),当发生这种情况时,你的POST被重定向到GET请求,这就是服务器响应的原因,就像你试图检索所有付款信息。 其他需要注意的是你的json数据实际上是无效的,因为它包含一个尾部,在'note'值之后,所以这可能也是一个问题。 我想你可能也会在头文件中缺少Content-Length标题。 我建议使用json模块来创建你的json数据: values = json.dumps({ "c ...
  • 尝试将所有内容读入字符串: html = urllib.urlopen(page).read() soup = BeautifulSoup(html) 虽然BS文档说传递一个打开的文件对象很好,但尝试这样做是个好主意。 如果它仍然失败,则意味着它与BS无关。 在这种情况下, print html以查看您收到的内容。 也许这只是因为你从python脚本或类似的东西访问它时没有登录到网站。 Try reading everything into a string: html = urllib.urlopen( ...
  • 以下是Python文档中的一个示例,根据您的代码进行了调整: import cookielib, urllib2 cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) request = urllib2.Request(url) response = opener.open(request) Here's an example from Python documentation, ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。