python函数似乎先调用自己然后点

时间:2019-01-21 10:58:24

标签: python python-3.x function

我正在尝试了解another answer中的代码:

import socket
import sys
import time

def get_lock(process_name):
    # Without holding a reference to our socket somewhere it gets garbage
    # collected when the function exits
    get_lock._lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)

    try:
        get_lock._lock_socket.bind('\0' + process_name)
        print 'I got the lock'
    except socket.error:
        print 'lock exists'
        sys.exit()

get_lock.开头的两行如何工作?它不像是一个类实例,您正在使用它的方法。

0 个答案:

没有答案